# About Me 😎

A cyber security enthusiast, who loves breaking Applications, networks and Active Directories 💻.

### Contact me 💌

**Twitter:** [*@noob\_pikachu*](https://twitter.com/noob_pikachu)\
**Email:** [*ankit.bharathan@owasp.org*](mailto:ankit.bharathan@owasp.org)\
**Linkedin:** [*ankitbharathan*](https://www.linkedin.com/in/ankitbharathan/)

### Certifications 📄

* <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-MfCejm2RJQn_nYLyGDv%2F-MfCfOkb4Z76RvoOCOlp%2Fimage.png?alt=media&amp;token=6419a02b-2207-4add-bcbd-f9ef05379fe8" alt="" data-size="original"> <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-MfCejm2RJQn_nYLyGDv%2F-MfCg5btfB-lu5zNNK3C%2FPWK-OSCP-badge.png?alt=media&amp;token=75d6e6b7-c413-403f-bc7d-069008ba9e98" alt="" data-size="original"> <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-MfCejm2RJQn_nYLyGDv%2F-MfCgAPMZJxuHnxHGv1P%2FCTP-OSCE-badge.png?alt=media&amp;token=4498e432-5a10-403d-a68c-3c9c4e68c2e7" alt="" data-size="original">&#x20;

* &#x20;<img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LriqRUd9-ajvUNw2__w%2F-LriqbHDMmGicXLcrOU7%2Fimage.png?alt=media&amp;token=c46d14ca-79bc-4c18-b393-403672a9cc08" alt="" data-size="original"> <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LnqENXBxHo_bdzrywEg%2F-LnqFpPNuc4FIoMMaARq%2Fecppt_v2_certificate_sm.png?alt=media&amp;token=ba0d1896-bd00-4fbb-bebd-aabe0dd19d22" alt="" data-size="original">\
  &#x20;  <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-MIP0OjtDpba_l4yS_tC%2F-MIP15JMM40OaLW0mHIH%2Fimage.png?alt=media&amp;token=f6c5f66b-c468-4615-bd44-36a635665b58" alt="" data-size="original">&#x20;

* &#x20; <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LnqENXBxHo_bdzrywEg%2F-LnqGE5o_Clgw3jOeLeG%2Fredteamprofessional.png?alt=media&amp;token=ef5c6b26-b65e-422c-9a41-a0a2bb371f1a" alt="" data-size="original"><img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-MEwbRsRB94xTrjVssvJ%2F-MEwbkY5qS2xfC3W4n2V%2Fredteamlabshield.png?alt=media&amp;token=a6256a6c-e427-46a9-9434-8eaafc719b02" alt="" data-size="original">&#x20;

* &#x20; <img src="https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LnqENXBxHo_bdzrywEg%2F-LnqGrvNGn1TXSw8uhtf%2FCPSA_CRT_540_470.png?alt=media&amp;token=8f2a08b8-c969-4e7d-84f2-c682be45c38b" alt="" data-size="original">&#x20;


# MITM/SSL pinning protection bypass for android applications

This post lists down a few of the MITM/SSL pinning protection bypass techniques which I found useful during my android application security assessments.

### Xposed framework modules

![Xposed Framework](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lo-dZVidCLJQxEOuz8h%2F-Lo-jYdUGnN_FfwUGXfQ%2Fimage.png?alt=media\&token=45cf89be-37b3-4303-94a4-bce3100d144e)

There are multiple [***Xposed***](https://www.xda-developers.com/xposed-framework-hub/) modules available to get this work done.These modules leverages techniques such as hiding root process, APK, fuction hooking, etc to bypass such protections. Below are the links to few of these modules which has helped me in the past.

| **Name**             | Link                                           |
| -------------------- | ---------------------------------------------- |
| JustTrustMe          | <https://github.com/Fuzion24/JustTrustMe>      |
| SSLUnpinning\_Xposed | <https://github.com/ac-pm/SSLUnpinning_Xposed> |
| TrustMeAlready       | <https://github.com/ViRb3/TrustMeAlready>      |

### Frida&#x20;

[***Frida***](https://www.frida.re) is a dynamic instrumentation framework which can be used to inject javscript snippets or library into native apps.There are multiple frida scripts available for bypassing ssl pinning. I am listing few of them below. It works for me most of time.

| Name                                   | Link                                                                                      |
| -------------------------------------- | ----------------------------------------------------------------------------------------- |
| root-ssl-pin-bypass.js                 | <https://gist.github.com/parad0xer/3ecc3526b9812be9f8374b2abbd91221>                      |
| Universal Android SSL Pinning Bypass   | <https://codeshare.frida.re/@pcipolloni/universal-android-ssl-pinning-bypass-with-frida/> |
| Universal Android SSL Pinning Bypass 2 | <https://codeshare.frida.re/@sowdust/universal-android-ssl-pinning-bypass-2/>             |

### Objection

[***Objection***](https://github.com/sensepost/objection) is a frida powered framework used for runtime mobile exploration.This can also be used to automate the SSL pinning bypass procedure.

![Source:https://github.com/sensepost/objection](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lo51VZq3yutfKwKjjEO%2F-Lo5RTqcsnaO-gHs8eu2%2Fandroid_ssl_pinning_bypass.png?alt=media\&token=3b8f7b97-9f10-496c-a006-2f0195e6f59b)

### Overwrite certificates

Sometimes certificates are stored inside application folder which can be replaced with custom certificates. This will require you to decompile the application and locate any certificates inside the application folders. Replace the cert or put Burp's certificate inside the folder and recompile the application. For signing the application you can use [***sign.jar***](https://github.com/appium/sign) and then install the application to inspect traffic using burp. &#x20;

![Certificate inside assets folder](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lo-dZVidCLJQxEOuz8h%2F-Lo-zWo6rFdf9-WefKzb%2Fimage.png?alt=media\&token=b07aa7b7-0f31-4ab3-a983-d4df4714e8c9)

### Network security config.xml

network config file  `/res/xml/network_security_config.xml` can be modified to intercept the application traffic.

Read more about [***network security config***](https://developer.android.com/training/articles/security-config)&#x20;

![Network\_security\_config.xml](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lo-dZVidCLJQxEOuz8h%2F-Lo17s-EGd9k1OpGAQaA%2Fimage.png?alt=media\&token=c0ba01bb-b993-4aa3-99ca-e6cbc5e0b0e2)

Replace the XML file with code below and recompile the application to intercept traffic.

{% code title="network\_security\_config.xml" %}

```markup
<network-security-config>
   <base-config>
       <trust-anchors>
           <!-- Trust preinstalled CAs -->
           <certificates src="system" />
           <!-- Additionally trust user added CAs -->
           <certificates src="user" />
       </trust-anchors>
   </base-config>
</network-security-config>
```

{% endcode %}

### Keystore manipulation

It is possible to manipulate BKS file which contains CA for SSL pinning. Most of the time it is stored inside the `/res/raw` folder. These BKS files are generally accessible without any password or the password can be found hardcoded inside the application. In a similar situation one can edit the BKS file to put a custom certificate to intercept the traffic.&#x20;

In below example, I decompiled the application using apktool and went to `/res/raw` folder and found a BKS file, the password for which was hardcoded.

![BKS file password](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LoP7oMnEoFbj3kc3iRG%2F-LoPBs2DS9NhBi1IcuC6%2Fimage.png?alt=media\&token=7eb718bf-6951-4f8b-8ce3-4bca58d3f030)

![Certificate inside BKS](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lo-dZVidCLJQxEOuz8h%2F-Lo0GtMOKFlEos8N6fLw%2Fimage.png?alt=media\&token=41370943-3fbe-41bd-a0ca-fb7b6cab2f2d)

I  added burp's CA to the BKS store and could bypass the MITM restriction.&#x20;

### Patching Application code

It is generally possible to reverse the certificate pinning code to bypass the restriction. It will require understanding of the code and the process may differ most of time.

Below are few of the examples where people have reversed the application code to bypass MITM restriction.

| Name              | Link                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| SSLPinningExample | <https://dl.packetstormsecurity.net/papers/general/android-sslpinning.pdf>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| OKhttp3           | <https://blog.securityevaluators.com/bypassing-okhttp3-certificate-pinning-c68a872ca9c8>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| pokemon go        | <p><a href="https://www.insidevcode.eu/2016/08/31/pokemon-go-0-35-0-remove-ssl-pinning/"><https://www.insidevcode.eu/2016/08/31/pokemon-go-0-35-0-remove-ssl-pinning/></a></p><p><a href="https://eaton-works.com/2016/07/31/reverse-engineering-and-removing-pokemon-gos-certificate-pinning/"><https://eaton-works.com/2016/07/31/reverse-engineering-and-removing-pokemon-gos-certificate-pinning/></a></p><p><a href="https://matalamaki.fi/2016/08/30/removing-certificate-pinning-from-pokemon-go-without-going-native/"><https://matalamaki.fi/2016/08/30/removing-certificate-pinning-from-pokemon-go-without-going-native/></a></p> |
| FBUnpinner        | <https://github.com/tsarpaul/FBUnpinner>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |


# Certified Red Team Professional

My take on the Certified Red Team Professional (CRTP) certification offered by Pentester Academy.

![Source: https://www.pentesteracademy.com/activedirectorylab](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LnxVJWFPX_KC5PU6gkb%2F-Lny84eV9eyoS6cgf1TZ%2Fimage.png?alt=media\&token=baeecab1-7765-40f8-b5da-737e08f0a231)

{% hint style="danger" %}
Note: [This is Not a Sponsored Post](https://techcrunch.com/2009/05/24/this-is-not-a-sponsored-post-paid-conversations-credibility-the-ftc/).
{% endhint %}

### What is CRTP?

[*CRTP*](https://www.pentesteracademy.com/activedirectorylab) is a certification offered by [*Pentester Academy*](https://www.pentesteracademy.com/) which focuses on attacking and defending active directories. The certification course is designed and instructed by[ *Nikhil Mittal*](https://twitter.com/nikhil_mitt), who is an excellent Info-sec professional and has developed multiple opensource tools. Nikhil has also presented his research in various conferences around the globe in the context of Info-sec and red teaming.&#x20;

He blogs regularly at [http://www.labofapenetrationtester.com](http://www.labofapenetrationtester.com/)

### Why should I take CRTP?

This Certification is made for people who are curious about red teaming and active directory security.

‌ Unlike other certifications, CRTP will teach you everything with an assume breach methodology where an attacker has an initial foothold inside an active directory environment and wants to move laterally to attain the highest privilege in an organization. As a defender, you will learn how attackers move laterally and attain these privileges so that these situations can be avoided to safeguard the active directory environment.&#x20;

Another reason which makes this certificate unique is the fact that it will teach you everything in a fully patched and updated environment where you will be using only using insecure configurations and administrative mistakes to complete your objectives.

### Who can take CRTP?

I feel that the course content is beginner-friendly. Anyone who has basic pentesting knowledge and understands concepts like reverse shells, privilege escalation, lateral movement, etc can directly opt for CRTP.

### Lab and Training materials

After registering for CRTP,  you will be offered a VPN config along with RDP credentials which will be used to access the labs. I opted for the one month lab which costed me around 300$. This lab will be an active directory environment where one can practice multiple challenges and attack vectors in the context of active directory and windows security. The training material consists of videos and slides which will demonstrate techniques such as Privilege escalation, lateral movement, bypassing security measures and persistence, This will also demonstrate how to safeguard an active directory environment. The training material also consists of multiple objectives which are fun to practice inside the lab environment. Author has also created walk through videos for every objective given which is beneficial in case you are stuck with any of the lab objective. The course content is very informative and beginner-friendly, it has helped me extensively during my penetration testing and red team projects later on.

### Examination

I took the examination on *9th August 2019* and was provided with a VPN config which I used to connect to my rescue box, a domain joined windows machine. I was given the objective to get OS command execution on 5 machines spread across the domain within 24 hours using the rescue box.&#x20;

&#x20;I completed all my objectives and submitted a detailed report within 14 hours. The support team quickly acknowledged that they have received the report and will be sending the result in 48 hours.&#x20;

{% hint style="info" %}
Please note that even if you cannot compromise all the boxes, it is still possible to clear the exam if your report is of top quality.
{% endhint %}

The next morning I received a mail stating the i have cleared the examination.They even announced the same on twitter.\*yaaaay\*🚬🍻

![Exam Result](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lnve_8KzbhCNbMqZdPU%2F-Lnw3SmfSswKOzaXO4bZ%2Fimage.png?alt=media\&token=98567f0d-7fc7-498c-89a0-a5fe485f13de)

![https://twitter.com/SecurityTube/status/1160866564230402048](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-Lnve_8KzbhCNbMqZdPU%2F-Lnw4wZBYE7ZoVaKgm3S%2F2019-09-04%2014_44_14-Window.png?alt=media\&token=8555618e-bece-4983-bdc0-aaee32515dfd)

### My thoughts on CRTP

This course helped me in learning and practicing a lot of different techniques which is bound to help me in my future endeavors.\
\
I believe any one who has prior experience with active directory pentesting or have gone through the course material thoroughly can clear this exam easily.&#x20;

My next goal is to clear [*CRTE* ](https://www.pentesteracademy.com/redteamlab)which is an advance version of this course.

Below are few of the interesting stuff's you get to learn during this course.&#x20;

{% tabs %}
{% tab title="Enumeration" %}

* Users, Policies, ACL, etc
* Hunting local admins.
* Session enumeration.
* Delegations.
* Trusts.

{% endtab %}

{% tab title="Lateral movement & privilege escalation" %}

* Abusing SQL trusts.
* Credential Dumping.
* Domain Trust and ACL abuse.
* Kerberoast related attacks.
* Cross forest Attacks.
* impersonation.
  {% endtab %}

{% tab title="Persistence" %}

* Skeleton Key.
* customs SSP.
* Golden Ticket.
* Silver Ticket.
* Admin SD Holder.
* DcSync.
* AdminSDholder.
* DcShadow.
  {% endtab %}

{% tab title="Defenses and bypass" %}

* Antivirus bypass.
* Amsi bypass.
* ATP bypass.
* EDR bypass.
* Laps.
* Paw.
* Red Forest.
  {% endtab %}

{% tab title="Tools" %}

* Mimikatz.
* Rubeus.
* Kekeo.
* Powersploit.
* Nishang.
* PowerupSQL.
  {% endtab %}
  {% endtabs %}

Read more about this [*here*](https://www.pentesteracademy.com/redlabs).

### References&#x20;

> 1. <https://adsecurity.org/>
> 2. <http://blog.harmj0y.net/>
> 3. <http://www.labofapenetrationtester.com>
> 4. <https://pentestlab.blog>
> 5. <https://blog.stealthbits.com>
> 6. <https://blog.netspi.com>
> 7. <https://ired.team>
> 8. <https://github.com/infosecn1nja/AD-Attack-Defense>
> 9. <https://github.com/NetSPI/PowerUpSQL/wiki/PowerUpSQL-Cheat-Sheet>


# NAC Bypass Cheatsheet

This post lists down a few of the techniques which can be used to bypass Network Access Control solutions(NAC).

### Pre-connect Scenario

In a pre-connect scenario decisions to grant access control rights are made before granting any access to the network resources.

* **Mac Spoofing**\
  It is possible to spoof the mac address of following devices and obtain network access.

1. Physical devices like old VOIP phone, Printers, cameras etc may not support 802.1x authentication and mac addresses assigned to these devices can be spoofed to obtain IP address.&#x20;
2. Physical access to 802.1x authenticated  VOIP phones, printer, etc may disclose mac and IP info from the network settings menu, stickers on the backside, etc.
3. Boot menu of certain workstations, laptops etc may disclose mac address.

{% code title="macchanger" %}

```bash
macchanger -m XX:XX:XX:XX:XX:XX
```

{% endcode %}

* **VOIP Hopping via CDP packets**\
  CDP protocol can be abused to hop the VLAN and obtain IP addres&#x73;**.**&#x20;

&#x20;       [**Voiphopper**](https://tools.kali.org/sniffingspoofing/voiphopper) tool can be used to execute this attack.

{% code title="VOIPhopper Example" %}

```bash
voiphopper -i eth0 -c 1 -E 'SIP00070EEA5086' -P 'Port 1' -C Host -L   'Cisco IP Phone 7940' -S 'P003-08-8-00' -U 1
```

{% endcode %}

* **VLAN Hopping via DTP Packets**\
  It is possible to hop vlans by abusing DTP protocol.\
  \
  &#x20;[***Frogger***](https://github.com/nccgroup/vlan-hopping) can be used to execute such attacks.

```bash
root@kali:/opt/# git clone https://github.com/nccgroup/vlan-hopping
root@kali:/opt# cd vlan-hopping/
root@kali:/opt/vlan-hopping# ls
frogger.sh  LICENSE  README.md
root@kali:/opt/vlan-hopping# ./frogger.sh
```

* **Pre-authenticated device**\
  Pre-authenticated devices can be used to bypass NAC solutions **.** In this situation an attacker will place a rogue device such as a raspberry pi between supplicant and authentication server. The traffic will then flow through the rogue device placed by the attacker.<br>

![https://twitter.com/dafthack/status/610468589569638400?lang=en](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LoSOSL8_f_cNUrntzP4%2F-LoSSWfw4_3FDV_Jt4ot%2Fimage.png?alt=media\&token=e5fa87ba-9aef-488a-a49f-ab2bbf515f9e)

| Name         | Link                                                |
| ------------ | --------------------------------------------------- |
| Nackered     | <https://github.com/p292/NACKered>                  |
| Fenrir       | <https://github.com/Orange-Cyberdefense/fenrir-ocd> |
| Silentbridge | <https://github.com/s0lst1c3/silentbridge>          |
| BITM         | <https://gitlab.com/warpnet/BitM>                   |

* &#x20;**Physical access to the network switch**\
  Obtaining physical access to the network switch and changing the configuration is one of the toughest but foolproof way of bypassing NAC solutions **🤢.**
* **Probe Request**\
  Fire up [***wireshark***](https://www.wireshark.org/) and check for MAC addresses in probe request. Try spoofing the MAC gathered from probe request.

### Post-Connect Scenario&#x20;

In a post-connect scenario you are allowed to the network for a small period of time and a set of checks are ran against your endpoint. If the endpoint fails to meet the requirements, it will be disallowed to use any resource further.

* **Mac randomization** \
  As mentioned before in a post-connect scenario, it is possible to use the network resources for a small period of time while a requirement check is done. In this situation  an attacker can change his MAC address to attain a new IP address prior to getting blocked and continue using the network resources.\
  \
  Below is a small python script which I made to automate this.

{% code title="randommac.py" %}

```python
#!/usr/bin/python
import subprocess
import sys
import threading
import time



class MyThread (threading.Thread):
    die = False
    def __init__(self, name):
        threading.Thread.__init__(self)
        

    def run(self):
        while not self.die:
            print "changing MAC Adress \n\n" + (time.ctime())
            subprocess.call(["sudo","ifconfig","eth0","down"]) # change interface if required
            subprocess.call(["sudo","macchanger","-A","eth0"]) # change interface if required
            subprocess.call(["sudo","ifconfig","eth0","up"]) # change interface if required
            print "MAC Changed\n"
            time.sleep(50) # mac adress will change in 50 seconds. 

    def join(self):
        self.die = True
        print "bye"
        sys.exit(1)

if __name__ == '__main__':
    f = MyThread('first')
    f.start()
    try:
        while True:
            time.sleep(2)
    except KeyboardInterrupt:
           f.join()
```

{% endcode %}

![Random mac ](https://2246521381-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnqEDCMlCBTf7EMdx0J%2F-LoXH_ghDp_25cNIb0uH%2F-LoXJxsfQQAra1asXwff%2Fimage.png?alt=media\&token=216f1edd-e6a0-4714-81b8-638b2d72f960)

* **UDP Filtering**\
  Sometimes NAC solutions will only disallow TCP connections but UDP connections would still be allowed and an attacker can leverage this to conduct NETBIOS scan in order to obtain IP and MAC addresses.

{% code title="NBTSCAN" %}

```bash
root@kali:~/Desktop# nbtscan 192.168.112.xx
Doing NBT name scan for addresses from 192.168.112.xx

IP address       NetBIOS Name     Server    User             MAC address      
------------------------------------------------------------------------------
192.168.112.xx    xxx              xx        xx            00:00:00:xx:xx:xx
```

{% endcode %}

* **Captive Portal Bypass**<br>

  [***Here***](https://blog.0katz.ca/bypassing_nac.html) is great post on bypassing captive portals. Kudos to [***0KATZ***](https://blog.0katz.ca/bypassing_nac.html) for this blog pos&#x74;**.**\
  \ <br>

#### **Something missing here? Reach me** [***@noob\_pikachu***](https://twitter.com/noob_pikachu)&#x20;


