Tuesday, 4 October 2016

Understand CTF [Capture The Flag] for Beginners

Hi friends, I am CodeNinja a.k.a. Aakash Choudhary.

In this article we will learn about basics of CTF

=========================================================

Q1: What is CTF?
ANS:
CTF means Capture the Flag. Creator of CTF Challenge hide their flags in their challenges. And as pentester we have to find that flag.

Challenger make a vulnerable machine for us so that our skill increase by solving their CTF


Q2: What types of CTF are there?
ANS:
Many  like :->

1. webapp : where we have to find vulnerability using web application.

2. crypto : Just to crack some passwords or else.

3. reverse engeering : where we use some reverse engeering knowledge to solve

4. shellode

I like to solve  "boot2root" ctfs. In this we have to root the server and find flag which is placed in root folder.

Q3: What knowledge and tools require?
ANS:
Knowledge of programming language, finding vulnerabilities knowledge etc etc

Tools mainly i use :->

1. netdiscover
2. nmap
3. browser
4. browser-addons
5. burpsuite
6. online sites like :  convert  hex to ascci etc
7. sqlmap
8. curl
9. dirb
10.fuzzdb/seclists
11. metasploit
12. exiftool
13. nikto
        14. wireshark

But Knowledge of LINUX is essential and bonus for us.


Q4: How to start to play CTFs?
ANS:
First these are methodologies :->
1. Host Discovery
2. Port Scanning
3. Service Enumeration
4. Privilege Escalation

Here are  common steps to solve ctf.


1. First check IP Address of CTF Machine
netdiscover -i <INTERFACE NAME Like : eth0> -r 192.168.43.1/24

or

netdiscover -r 192.168.43.1/24     [If don't know interface]


or

netdiscover -r 192.168.1.1/24

2. After get IP  chek
1) what services are running on each port?
2) What information can be obtained about each service?
3) what os it using?
4) what  version it using?

Tools which use for this purpose :-> nmap,netcat,metasploit,smbclient,filezilla,ssh etc etc


Lets use nmap


nmap -sV -A -p- 192.168.43.77

or

nmap -T5 -p- -oA 192.168.43.77

3. Note those information in text files. Its mean We have to do lots of Information Gathering  and note them for future use.


Lets discuss some scenarios ::::::

Case 1  :  port 80 or 8080 open then  it is HTTP or HTTPS and we can browse it in   browser

Case 2  :  port 22 open mean ssh open so we can connect to remotly connection
  For this we have to find password and user info.

Case 3  :  32258 port squid proxy open. Mean we can use that proxy port just like we   use burpsuite proxy  ex: 127.0.0.1:8080

But here we can use :-> 192.68.43.77:32258


Case 4  :  Some Apache version, PHP Version, OS Information we get from result.
Might be they are using old versions and we can find exploits for them


Case 5  :  Check which cms there like joomla,drupal,wordpress.
Use grabcms to check cms
Use wpscan,cmsmap [to find cms vulnerabilities]


                                                    ::::::: BOOT 2 ROOT :::::::

4. Ok now. Our next step is top open website and check it completely


1. open website. and in one tab see its source code and in another tab open
           robots.txt
  1.1 robots.txt :-> Here i want to see some important directories. like
admin,config

  1.2 source-code :-> Here i will check js-codes,meta-tags,comment-
section,wordpress-version etc


  1.3 Application-Area : Mean i want to see some user-entry points like login page
 ,register page, comment section.
So i am looking for vulnerabilities like : sql
injection,xss,rfi,lfi,code-execution,xxe  etc




2. Then i use nikto to see some directories and vulnerabilities.Also using dirbuster
           to check hidden directories.

3. Burpsuite using for check response and request. And there are multi functions
  which burpsuite can use like scanning,spider,intruder,repeater etc
 
4. I will note everything till now what i got.



5. Main motive for boot2root is to first acceess shell on site somehow and then root it
   after get information about kernel version


So how to root it ?
Well we will learn these in my upcoming solutions.We will learn many techniques to root.


==================================================================

Q:So when we doing nmap and other techniques as information gathering then what information actually we want to gather?
ANS:
Service Enumeration :->

Find services of target. As Pentester our goal is :->

        1) What services are running on the target? ::: http,https,ssh etc

2) What version are they running? ::: Apache or can say Web Server Version or PHP/ASP Version

3) Are there any plugins attached to the services? [If CMS(wordpress) then what plugin it using. or can say any other plugins our target using]

4) What versions are the plugins?


5) Are you able to identify any service misconfiguration?
[web server, application server, database, framework, and custom code.]
Misconfiguration on those as example

Detail example :->

1. Check OS, Web/App Server, DBMS might be they using out of date software.
2. Are any unnecessary features enabled or installed (e.g., ports, services, pages, accounts, privileges)?
More info :->
https://www.owasp.org/index.php/Top_10_2013-A5-Security_Misconfiguration




6) Is there a web server?

7) Is it off the shelf? (wordpress)

8) Version?

9) Plugins and Versions?

10) Misconfigured?


IMPORTANT PORTS :->

                Port 21 FTP vstfpd Version ?
Port 22 SSH OpenSSH Version 4.3
Port 25 SMTP Service? Version ?
Port 80 HTTP Apache Version 2.0.55 (Also running PHP version 5.1.2)
Port 110 POP3 Openwall popa3d Version ?
Port 143 IMAP UW Imapd 2004.357

Website Enumeration :->

        1. Check source page of website to see information

Like :-> Any interesting Javascript code
Check Meta Tags to see any informtion like author info,cms info etc
2. Check robots.txt

3. Dirbuster to check hidden directories. Also can use other alternative like zap,burpsuite,nikto

4. Check footer to see information like "Powered By" or other things which might be exploit

5. wpscan,cmsmap,nikto, sqlmap  etc like tools will be handy use
6. Find exploits after finding useful information from above steps

Tools :-> searchsploit & Metasploit

7. Always keep FUZZING in box [fuzzdb & seclists] Many wordlists will be here

8. For rooting knolwedge of LINUX important


So for FULL DETAIL Guide :->

http://blog.nullmode.com/blog/2013/10/31/de-ice-s1-dot-100-level-1-a-beginners-guide/

=================================================================

Some Important Links :->

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

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

3. asciitohex.com

4. itsecuritysector.com

5. www.decode.org/?q=vasbfrp_syntvf_jrybirpbbxvrf

6. www.url-encode-decode.com

7. Great Password/name/directory wordlists!!
    https://github.com/danielmiessler/SecLists/tree/master/Passwords

8. Quick URL Encode/decode
    http://meyerweb.com/eric/tools/dencoder/

9. Various online text conversions
    http://www.unit-conversion.info/texttools/strip-tags/#data

10. TTY Shells help  :->  http://netsec.ws/?p=337

11. Learn about  "AWK" & "SED"
      http://www.tutorialspoint.com/awk/awk_basic_examples.htm
      http://sed.sourceforge.net/sed1line.txt

12. Shellshock

     resources.infosecinstitute.com/practical-shellshock-exploitation-part-1/

    resources.infosecinstitute.com/practical-shellshock-exploitation-part-2/

====================================================================

BONUS :->
These will help while solving CTF


1. Binary to ascii translator :-> https://paulschou.com/tools/xlate/

2.Steganography :-> steghid :-> steghide --extract -sf name.jpg -xf output.txt

3. ROT13 Decode :–> http://www.decode.org/

4.Online qrcode decoding – http://zxing.org/w/decode.jspx

5. Morse code decoder – http://morsecode.scphillips.com/translator.html

6. Important command :->
file filename
strings filename
exiftool filename

7. rev  => echo abc | rev     ===> cba

==================================================================

Hope you like it

Thanks 

0 comments:

Post a Comment