CTFs

Crackstation.net : NTLM, md4, md5 hashes match with existing hashtable from crackstation

Some useful commands:

  1. cat | head -n <line_number> | tail -1 : get n’th line_number

  2. strings reversing1 | egrep “^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$” | while read line ; do echo $line | base64 -d | cat -v && echo “”; done

    base64 encoded text regex

  3. echo “obase=16; <decimal_number>” | BC_LINE_LENGTH=0 bc | awk ‘{ print (length($0) % 2 == 0) ? $0 : 0$0; }’ : decimal number to zero padded hex

  1. /bin/cat $(find / -name flag.txt): find all files with name flag.txt and paste their content

  2. echo ‘<hex_string>’ | awk ‘{ print (length($0) % 2 == 0) ? $0 : 0$0; }’ | xxd -p -r > <output_file> : create binary file from hex strings

  3. cat <(python -c “print((‘A’ * 76) + ‘\x08\x87\x04\x08’)”) - | ./authme : redirect into executable stdin and then keep going

  4. ascii_char=\((printf “\)(printf %x <decimal_ascii_code>)” | xxd -p -r) : ascii code to characters

  5. { echo “name”; echo ‘a_reAllY_s3cuRe_p4s$word_56b977’;} | cat : echo two lines by including them in curly braces

9/ Openssl commands:

  1. openssl genrsa -out <output_key_name> : generate a rsa based private public key pair

  2. openssl req -in -text -noout : view certificate signing details

  3. openssl x509 -in <c.cer> -inform -text -noout: examine certificate content : formats can be pem or der

  4. openssl pkcs12 -export -inkey <key_file> -in <cert_file> -certfile <parent_certs> -out <output_name> : get pkcs12 file ; needs key_file, cert_file and parent certificates

  5. openssl x509 -req -in <child_csr> -CA <parent_certificate> -CAkey <parent_key> -CAcreateserial -out <output_child_name> -days <validity_days> -sha256 -extfile : sign child csr with parent

  6. openssl rsa -pubin -in <public_key_file> -text: examine modulus and exponent of RSA public key

  7. openssl pkcs12 -info -in : pkcs12 file details

  8. openssl pkcs12 -in <input_pfx_file> -clcerts -nokeys -out <output_certificate_file> : extract certificate files from pkc file

  9. openssl rsa -in <private_key_file> -text : evaluate rsa private key details: modulus, exponent and so on.

  10. openssl req -addext -outform pem -out <out_csr_name> -key <input_csr_key> -new : generate csr file with extension

  1. https://github.com/Ganapati/RsaCtfTool : rsa ctf tool to analyze using various public and private keys, some simple decryption tries as well. it helps uncipher files using rsa private key as well

  2. echo “U2VjcmV0IG1lc3NhZ2U=” | base64 -d : simple base 64 decoding directly from command line

  3. cyclic : generate a cyclic number of string inputs of specific length; used in several cases of buffer overflow

  4. sudo pip install capstone; pip install ropgadget; : shellstorm script to find rop exploitation on various elf, pe , mach o binaries on various architectures.

  5. shellstorm.org : so you want to have exploits to various shells, you have binaries and tools to let you exploit here.

  6. radare2 : analysing any binary for reversing ; https://insinuator.net/2016/08/reverse-engineering-with-radare2-part-1/ tutorials on using radare2

  7. ltrace : gives all the library calls and system calls made by the program

  8. strace : gives all the system calls made by the program to the kernel

  9. https://github.com/slimm609/checksec.sh : this script can give you info about different type of executables and their sections

Forensics:

  1. apktool -d : decompiles any android app

  2. sox <audio_file> -n spectrogram : give a spectrogram of any wav file: directly available on linux archives

Binary forensics:

  1. xxd -g1 <binary_file>: g means the number of bytes to group by : this is used to print the binary file’s hex code

  2. strings

  3. dd skip=<start_offset> count= if=<input_file> of=<output_file> bs=1 : get a binary file from an existing binary file using offset and count of number of bytes

  4. printf | dd conv=notrunc of= bs=1 seek= : patch a binary with bytes at offset.

    example: printf ‘\x53\xef’ | dd conv=notrunc of=ext-super-magic.img bs=1 seek=$((1024+56)) adds the bytes at the seek position . Useful when changing and adding headers to binary files

  5. file

  6. https://ide.kaitai.io/ : kaitai ide to analyze any binary : has it’s specific formats at formats.kaitai.io

  7. foremost :Recover files based on their headers, footers, and internal data structures. available as linux package

  8. binwalk : walk through the executable to find number of files and executable code : to extract use option -echo

  9. binwalk –dd=".*" <file_name> : extract any file type from binwalk; not just known files

  10. pngcheck : check the integrity of png files

  11. exiftool : metadata and exif information from file

  12. sudo apt-get install zbar-tools; zbarimg <img_with_qr> : decodes qr code from image

  13. https://blog.didierstevens.com/2008/04/09/quickpost-about-the-physical-and-logical-structure-of-pdf-files/ : learn about physical and logical structure of a pdf file

  14. get pdf-parser.py from ctf-tools : pdf-parser -v : get all malformed elements with todo prefix

    example: pdf-parser.py -v 1485.pdf | grep “todo”

  15. Stegano with gimp: Reveal hidden text in an image.

    1. Open the image with GIMP.
    2. Mode: Grain Extract.
    3. Filters -> Enhance -> Unsharp Mask -> Amout: ~10.0
  16. stegsolve, zsteg are easy to use as well.

Network and Web:

  1. Curl : -s, –silent: -v, –verbose: , -k –insecure: any connection doesn’t check certs.

  2. curl –cookie “<cookie_name>=<cookie_value>” : give a cookie and get something from the uri

  3. curl -X POST –data “=&=” : fetch using a post request with multiple parameters

    –data-binary : if you don’t want curl to work on the data

  4. curl -H ‘Content-Type: application/json; charset=UTF-8’ –data-binary ‘{"":""}’ : use a json request to fetch data from a server

  5. curl -d “=” –data-urlencode “=<value2_to_be_encoded>” -X POST " : fetch using post request and a urlencoded format to send to the server

  6. curl -l : gets the header only from a request.

Directory search : https://github.com/maurosoria/dirsearch : brute force a directory for files and folders

dirsearch.py -u -e

Dirbuster from owasp can be used to find dirs as well

nmap -p 443 –script ssl-cert : view certificate details for ssl-cert

scp username@from_host:file.txt local/directory : directly get a file from ssh server to local directory

scp file.txt username@to_host:/remote/directory/ : copy to ssh server

Tshark:

tshark -r -Y “data.len != 0” -T json -e tcp.stream -e data.data : Receive JSON-encoded structure of all TCP packets which contain data.

Display all frames from a network capture which comply with filter.

Add ‘-x’ for a full hex dump of the packets.

Password file cracking:

unshadow <passwd_file> <shadow_file> : combine passwd and shadow to crack linux pwd hashes

zip2john <zip_file> > <password_file> : Encode a zip file’s password in a format John can crack.

john <password_file> : –show option to show pwd after cracking it

SQLMAP:

sqlmap -u : automate the process of sqli attacks

–dbs: Discover databases in case an SQL vulnerability is previously found.

—tables -D : Discover tables in case an SQL vulnerability is previously found.

–dump -T

-D : dump a table of a databases

–method POST –data -p <field_to_attack> : using a post on specific field

GDB:

printf “%s”, 0x804894c : print a string

gdb <core_dump> : open a program with a core dump

run(r), quit(q), continue(q)

break *

or function to break at function name

info break : info about breakpoints

delete breakpoint

step, stepi, next, nexti, finish : i means one instruction and then stop to debugger

nexti : Execute one machine instruction, but if it is a function call, proceed until the function returns.

step: Continue running your program until control reaches a different source line, then stop it and return control to GDB.

finish(fin): Continue running until just after function in the selected stack frame returns. Print the returned value (if any).

print:

p i:

p/x i:

p arr:

p pArr

p *pArr@3

p *pArr

  • to dereference variables.

@[number] to print as an array of [number] elements.

/x for printing hexadecimal values.

x / : n: repeat count, f: display format, u: unit size

example: x /10xb $2

info variables : get all static and global variables

info locals: Print all local variables of current stack frame.

info args: Print all local arguments of current stack frame.

list(l) : print lines from a source file

disassemble(disas): print disassembly of the program

backtrace(bt): A summary of the call stack - one line per frame.

frame : Move to a specific frame from the backtrace to view locals or arguments.

info threads: status of all threads for the process

thread apply all : apply a singular command to all threads

e.g. thread apply all backtrace

thread : Make thread number threadno the current thread.

until : Continue running until a source line past the current line, in the current stack frame, is reached.

info

: show details about the address

e.g. info address system@plt

readelf: show the elf binaries info

info proc mappings: Report the memory address space ranges accessible in the program.

GDB settings:

display/i $pc: Display the machine instruction about to be executed each time execution stops.

set print pretty on: indented format print with one per line

dump memory <filename.bin> <start_addr> <end_addr> : dump binary from specific start to end address

set print elements : Set a limit on how many elements of an array GDB will print. Default is 200, 0 for unlimited

set print array-indexes on : Print the index of each element when displaying arrays.

set disassembly-flavor intel: change the disassembly-flavor format

set output-radix : Set the default base for numeric display.