-
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathliffy.py
More file actions
365 lines (335 loc) · 10.6 KB
/
liffy.py
File metadata and controls
365 lines (335 loc) · 10.6 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/usr/bin/python
import argparse
import json
import signal
import sys
import concurrent.futures
import urllib.parse
import requests
from core import Expect, Filter, Input, accesslog, data, proc, sshlog, DirTraversal
from core.rich_output import (
print_banner,
configure_output,
load_config,
create_default_config,
rich_print,
print_error,
print_success,
_config,
)
from core.ThreadManager import ThreadManager
from core.utils import configure_http_options, configure_runtime_options, HTTP_OPTIONS
from tests.test_liffy import (
test_data,
test_input,
test_expect,
test_proc,
test_access,
test_ssh,
test_filter,
test_directory_traversal,
test_null_byte,
test_zip_wrapper,
test_wrapper_scan,
test_oob_scan,
test_blind_scan,
)
def ping(url):
"""Check whether the target HTTP service is reachable."""
request_kwargs = {"timeout": HTTP_OPTIONS["timeout"]}
if HTTP_OPTIONS.get("proxy"):
request_kwargs["proxies"] = {
"http": HTTP_OPTIONS["proxy"],
"https": HTTP_OPTIONS["proxy"],
}
if HTTP_OPTIONS.get("verify_tls"):
request_kwargs["verify"] = True
try:
response = requests.head(url, allow_redirects=True, **request_kwargs)
return True
except requests.RequestException:
try:
response = requests.get(url, stream=True, **request_kwargs)
response.close()
return True
except requests.RequestException:
return False
def signal_handler(signal, frame):
print_error("\n\nYou pressed Ctrl+C!")
sys.exit(0)
def apply_auto_scan(args):
if not args.auto:
return
args.detection = True
args.directorytraverse = True
args.wrappers = True
args.blind = True
if args.oob_url:
args.oob = True
def main():
if not len(sys.argv):
print("[!] Not Enough Arguments!")
# TODO: Add usage
sys.exit(0)
# Parse args first to check for banner/color settings
parser = argparse.ArgumentParser()
parser.add_argument("url", help="URL to test for LFI", nargs="?")
parser.add_argument(
"-d", "--data", help="Use data:// technique", action="store_true"
)
parser.add_argument(
"-i", "--input", help="Use input:// technique", action="store_true"
)
parser.add_argument(
"-e", "--expect", help="Use expect:// technique", action="store_true"
)
parser.add_argument(
"-f", "--filter", help="Use filter:// technique", action="store_true"
)
parser.add_argument(
"-p", "--proc", help="Use /proc/self/environ technique", action="store_true"
)
parser.add_argument(
"-a", "--access", help="Apache access logs technique", action="store_true"
)
parser.add_argument(
"-ns",
"--nostager",
help="execute payload directly, do not use stager",
action="store_true",
)
parser.add_argument(
"-r",
"--relative",
help="use path traversal sequences for attack",
action="store_true",
)
parser.add_argument("--ssh", help="SSH auth log poisoning", action="store_true")
parser.add_argument(
"-l", "--location", help="path to target file (access log, auth log, etc.)"
)
parser.add_argument("--cookies", help="session cookies for authentication")
parser.add_argument(
"-dt",
"--directorytraverse",
help="Test for Directory Traversal",
action="store_true",
)
parser.add_argument(
"-t", "--threads", help="number of threads to use", default=5, type=int
)
parser.add_argument(
"--detection",
help="Only perform LFI detection, without attempting to get a shell",
action="store_true",
)
parser.add_argument(
"--null-byte",
help="Test for Null Byte Poisoning",
action="store_true",
)
parser.add_argument(
"--zip",
help="Test for ZIP wrapper exploitation",
action="store_true",
)
parser.add_argument(
"--wrappers",
"--wrapper",
dest="wrappers",
help="Detect common LFI stream wrappers",
action="store_true",
)
parser.add_argument(
"--wrapper-list",
help="Path to custom wrapper probe payload list",
)
parser.add_argument(
"--oob",
help="Send out-of-band callback probes",
action="store_true",
)
parser.add_argument("--oob-url", help="OOB callback base URL")
parser.add_argument(
"--blind",
help="Run blind LFI response-difference checks",
action="store_true",
)
parser.add_argument("--blind-list", help="Path to custom blind LFI probe list")
parser.add_argument(
"--auto",
help="Run a safe automatic scan plan",
action="store_true",
)
parser.add_argument(
"--encoding",
help="Use advanced encoding/bypass techniques",
action="store_true",
)
parser.add_argument(
"--waf-bypass",
help="Use WAF evasion techniques",
action="store_true",
)
parser.add_argument(
"--method",
help="HTTP method to use (GET/POST)",
default="GET",
choices=["GET", "POST"],
)
parser.add_argument(
"--post-data",
help="POST data (format: key=value&key2=value2)",
)
parser.add_argument(
"--headers",
help="Custom headers (format: Header1:Value1,Header2:Value2)",
)
parser.add_argument("--lhost", help="callback host for staged payloads")
parser.add_argument("--lport", help="callback port for staged payloads")
parser.add_argument("--read-file", help="file path to read with filter://")
parser.add_argument(
"-y",
"--yes",
help="use defaults for prompts and run non-interactively",
action="store_true",
)
parser.add_argument("--timeout", type=float, help="HTTP request timeout in seconds")
parser.add_argument("--proxy", help="HTTP(S) proxy URL")
parser.add_argument(
"--verify-tls",
help="verify TLS certificates instead of using insecure requests",
action="store_true",
)
parser.add_argument("--user-agent", help="custom User-Agent header")
parser.add_argument("--delay", type=float, help="delay between requests in seconds")
parser.add_argument("--retries", type=int, help="HTTP retries per request")
parser.add_argument(
"--json",
help="print a JSON run summary",
action="store_true",
)
parser.add_argument("--output", help="write JSON run summary to a file")
parser.add_argument(
"--quiet",
help="suppress normal terminal output",
action="store_true",
)
parser.add_argument(
"--no-color",
help="Disable colored output",
action="store_true",
)
parser.add_argument(
"--no-banner",
help="Disable banner display",
action="store_true",
)
parser.add_argument(
"--config",
help="Create default YAML configuration file",
action="store_true",
)
args = parser.parse_args()
# Handle config creation
if args.config:
if create_default_config():
print_success(
"Default configuration file 'liffy_config.yaml' created successfully!"
)
else:
print_error(
"Configuration file already exists! Delete 'liffy_config.yaml' first or edit it directly."
)
sys.exit(0)
# Load configuration and apply CLI overrides
load_config()
configure_output(
disable_colors=args.no_color,
disable_banner=args.no_banner,
quiet=args.quiet or (args.json and not args.output),
)
configure_http_options(args, _config)
configure_runtime_options(args)
# Show banner after configuration is loaded
print_banner()
if not args.url:
print_error("URL is required")
sys.exit(1)
parsed = urllib.parse.urlsplit(args.url)
if not parsed.query:
print_error("No GET parameter Provided")
pre_run_tasks = {
ping: "Checking Target: {0}".format(args.url),
}
with concurrent.futures.ThreadPoolExecutor(
max_workers=len(pre_run_tasks)
) as executor:
future_to_task = {
executor.submit(task, args.url): task for task in pre_run_tasks
}
for future in concurrent.futures.as_completed(future_to_task):
task = future_to_task[future]
try:
result = future.result()
if not result:
print_error("Target irresponsive")
sys.exit(1)
else:
print_success("Target looks alive")
except Exception as exc:
print(f"{pre_run_tasks[task]} generated an exception: {exc}")
apply_auto_scan(args)
tasks = []
if args.data:
tasks.append(test_data)
if args.input:
tasks.append(test_input)
if args.expect:
tasks.append(test_expect)
if args.proc:
tasks.append(test_proc)
if args.access:
tasks.append(test_access)
if args.ssh:
tasks.append(test_ssh)
if args.filter:
tasks.append(test_filter)
if args.directorytraverse:
tasks.append(test_directory_traversal)
if args.null_byte:
tasks.append(test_null_byte)
if args.zip:
tasks.append(test_zip_wrapper)
if args.wrappers:
tasks.append(test_wrapper_scan)
if args.oob:
tasks.append(test_oob_scan)
if args.blind:
tasks.append(test_blind_scan)
if not tasks:
print_error("Please select at least one technique to test")
sys.exit(0)
# Create enhanced thread manager
max_workers = getattr(args, "threads", _config.get("max_threads", 5))
rate_limit = _config.get("rate_limit_delay", 0.1)
thread_manager = ThreadManager(max_workers=max_workers, rate_limit_delay=rate_limit)
# Execute each selected technique once with the parsed CLI arguments.
results = thread_manager.execute_tasks(tasks, [args])
if args.json or args.output:
summary = {
"target": args.url,
"techniques": [task.__name__ for task in tasks],
"completed": thread_manager.completed_tasks,
"failed": thread_manager.failed_tasks,
"result_count": len(results),
}
rendered = json.dumps(summary, indent=2)
if args.output:
with open(args.output, "w") as output_file:
output_file.write(rendered + "\n")
if args.json:
print(rendered)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
main()