icoa-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/commands/connect.d.ts +2 -0
  2. package/dist/commands/connect.js +66 -0
  3. package/dist/commands/ctf.d.ts +2 -0
  4. package/dist/commands/ctf.js +472 -0
  5. package/dist/commands/files.d.ts +2 -0
  6. package/dist/commands/files.js +52 -0
  7. package/dist/commands/hint.d.ts +2 -0
  8. package/dist/commands/hint.js +107 -0
  9. package/dist/commands/lang.d.ts +2 -0
  10. package/dist/commands/lang.js +42 -0
  11. package/dist/commands/log.d.ts +2 -0
  12. package/dist/commands/log.js +36 -0
  13. package/dist/commands/note.d.ts +2 -0
  14. package/dist/commands/note.js +32 -0
  15. package/dist/commands/ref.d.ts +2 -0
  16. package/dist/commands/ref.js +63 -0
  17. package/dist/commands/setup.d.ts +2 -0
  18. package/dist/commands/setup.js +88 -0
  19. package/dist/commands/shell.d.ts +2 -0
  20. package/dist/commands/shell.js +55 -0
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.js +78 -0
  23. package/dist/lib/budget.d.ts +8 -0
  24. package/dist/lib/budget.js +29 -0
  25. package/dist/lib/config.d.ts +7 -0
  26. package/dist/lib/config.js +60 -0
  27. package/dist/lib/ctfd-client.d.ts +22 -0
  28. package/dist/lib/ctfd-client.js +161 -0
  29. package/dist/lib/gemini.d.ts +7 -0
  30. package/dist/lib/gemini.js +108 -0
  31. package/dist/lib/logger.d.ts +6 -0
  32. package/dist/lib/logger.js +59 -0
  33. package/dist/lib/translation.d.ts +1 -0
  34. package/dist/lib/translation.js +40 -0
  35. package/dist/lib/ui.d.ts +10 -0
  36. package/dist/lib/ui.js +59 -0
  37. package/dist/types/index.d.ts +125 -0
  38. package/dist/types/index.js +29 -0
  39. package/package.json +43 -0
  40. package/refs/ROPgadget.txt +67 -0
  41. package/refs/base64.txt +63 -0
  42. package/refs/bash.txt +79 -0
  43. package/refs/binwalk.txt +43 -0
  44. package/refs/bs4.txt +61 -0
  45. package/refs/checksec.txt +57 -0
  46. package/refs/curl.txt +73 -0
  47. package/refs/cyberchef.txt +78 -0
  48. package/refs/exiftool.txt +50 -0
  49. package/refs/ffuf.txt +73 -0
  50. package/refs/gcc.txt +66 -0
  51. package/refs/gdb.txt +83 -0
  52. package/refs/hashcat.txt +64 -0
  53. package/refs/hint.txt +42 -0
  54. package/refs/icoa.txt +36 -0
  55. package/refs/john.txt +74 -0
  56. package/refs/linux.txt +58 -0
  57. package/refs/nc.txt +64 -0
  58. package/refs/nmap.txt +57 -0
  59. package/refs/numpy.txt +59 -0
  60. package/refs/openssl.txt +75 -0
  61. package/refs/pillow.txt +67 -0
  62. package/refs/pwntools.txt +79 -0
  63. package/refs/pycrypto.txt +77 -0
  64. package/refs/python.txt +94 -0
  65. package/refs/r2.txt +85 -0
  66. package/refs/regex.txt +73 -0
  67. package/refs/requests.txt +83 -0
  68. package/refs/rules.txt +28 -0
  69. package/refs/scapy.txt +80 -0
  70. package/refs/sqlmap.txt +69 -0
  71. package/refs/steghide.txt +71 -0
  72. package/refs/struct.txt +61 -0
  73. package/refs/sympy.txt +77 -0
  74. package/refs/tshark.txt +65 -0
  75. package/refs/vim.txt +74 -0
  76. package/refs/volatility.txt +41 -0
  77. package/refs/z3.txt +78 -0
@@ -0,0 +1,67 @@
1
+ Pillow (PIL) Quick Reference
2
+ ============================
3
+
4
+ INSTALLATION
5
+ pip install pillow
6
+
7
+ BASIC USAGE
8
+ from PIL import Image
9
+
10
+ img = Image.open("image.png")
11
+ img.save("output.png")
12
+ img.show()
13
+
14
+ IMAGE INFO
15
+ img.size (width, height)
16
+ img.mode "RGB", "RGBA", "L", "1"
17
+ img.format "PNG", "JPEG", etc.
18
+ img.info Metadata dict
19
+
20
+ PIXEL ACCESS
21
+ px = img.load() Get pixel access
22
+ px[x, y] Get pixel value
23
+ px[x, y] = (R, G, B) Set pixel value
24
+
25
+ # Get all pixels
26
+ pixels = list(img.getdata())
27
+
28
+ CONVERSIONS
29
+ img.convert("L") Grayscale
30
+ img.convert("RGB") RGB
31
+ img.convert("RGBA") RGBA
32
+ img.convert("1") Black and white
33
+
34
+ OPERATIONS
35
+ img.resize((w, h)) Resize
36
+ img.crop((l, t, r, b)) Crop (left, top, right, bottom)
37
+ img.rotate(90) Rotate
38
+ img.transpose(Image.FLIP_LEFT_RIGHT) Flip horizontal
39
+
40
+ CREATE NEW IMAGE
41
+ img = Image.new("RGB", (width, height), (255, 255, 255))
42
+
43
+ COMMON CTF PATTERNS
44
+ # LSB steganography extraction
45
+ img = Image.open("steg.png")
46
+ px = img.load()
47
+ bits = ""
48
+ for y in range(img.height):
49
+ for x in range(img.width):
50
+ r, g, b = px[x, y][:3]
51
+ bits += str(r & 1) # Extract LSB
52
+ # Convert bits to bytes
53
+ message = bytes(int(bits[i:i+8], 2) for i in range(0, len(bits), 8))
54
+
55
+ # Hide data in pixels
56
+ for i, byte in enumerate(data):
57
+ x, y = i % img.width, i // img.width
58
+ r, g, b = px[x, y][:3]
59
+ px[x, y] = ((r & 0xFE) | (byte >> 7 & 1), g, b)
60
+
61
+ # Visual comparison
62
+ from PIL import ImageChops
63
+ diff = ImageChops.difference(img1, img2)
64
+ diff.save("diff.png")
65
+
66
+ # Extract text from image regions
67
+ region = img.crop((10, 10, 200, 50))
@@ -0,0 +1,79 @@
1
+ Pwntools Quick Reference
2
+ ========================
3
+
4
+ INSTALLATION
5
+ pip install pwntools
6
+
7
+ CONNECTION
8
+ from pwn import *
9
+
10
+ # Remote connection
11
+ r = remote("host", port)
12
+
13
+ # Local process
14
+ p = process("./binary")
15
+
16
+ # SSH
17
+ s = ssh("user", "host", password="pass")
18
+
19
+ SEND / RECEIVE
20
+ r.send(b"data") Send raw bytes
21
+ r.sendline(b"data") Send + newline
22
+ r.sendafter(b"prompt", data) Send after receiving
23
+ r.sendlineafter(b">", data) Sendline after prompt
24
+
25
+ r.recv(1024) Receive up to N bytes
26
+ r.recvline() Receive one line
27
+ r.recvuntil(b":") Receive until delimiter
28
+ r.recvall() Receive everything
29
+ r.interactive() Interactive mode
30
+
31
+ PACKING / UNPACKING
32
+ p32(0x41414141) Pack 32-bit (little-endian)
33
+ p64(0x41414141) Pack 64-bit
34
+ u32(b"\x41\x41\x41\x41") Unpack 32-bit
35
+ u64(data) Unpack 64-bit
36
+ p32(addr, endian='big') Big-endian pack
37
+
38
+ ELF ANALYSIS
39
+ e = ELF("./binary")
40
+ e.symbols["main"] Function address
41
+ e.got["puts"] GOT entry
42
+ e.plt["puts"] PLT entry
43
+ e.search(b"/bin/sh") Search for bytes
44
+ e.address Base address
45
+
46
+ ROP
47
+ rop = ROP(e)
48
+ rop.call("puts", [got_puts]) Call function
49
+ rop.raw(gadget_addr) Raw gadget
50
+ rop.chain() Build chain
51
+ rop.find_gadget(["pop rdi"]) Find gadget
52
+
53
+ SHELLCODE
54
+ shellcraft.sh() /bin/sh shellcode
55
+ shellcraft.cat("flag.txt") cat file
56
+ asm(shellcraft.sh()) Assemble shellcode
57
+
58
+ CRYPTO
59
+ xor(data, key) XOR data with key
60
+ xor_key(plain, cipher) Find XOR key
61
+
62
+ CONTEXT
63
+ context.arch = "amd64" Set architecture
64
+ context.os = "linux" Set OS
65
+ context.log_level = "debug" Debug output
66
+ context.terminal = ["tmux", "splitw", "-h"]
67
+
68
+ FORMAT STRING
69
+ fmtstr_payload(offset, {addr: value})
70
+
71
+ COMMON PATTERNS
72
+ # Buffer overflow
73
+ payload = b"A" * offset
74
+ payload += p64(ret_addr)
75
+ r.sendline(payload)
76
+
77
+ # Leak address
78
+ r.recvuntil(b"output: ")
79
+ leak = u64(r.recv(6).ljust(8, b"\x00"))
@@ -0,0 +1,77 @@
1
+ PyCryptodome Quick Reference
2
+ ============================
3
+
4
+ INSTALLATION
5
+ pip install pycryptodome
6
+
7
+ AES
8
+ from Crypto.Cipher import AES
9
+ from Crypto.Util.Padding import pad, unpad
10
+
11
+ # AES-ECB
12
+ cipher = AES.new(key, AES.MODE_ECB)
13
+ ct = cipher.encrypt(pad(data, 16))
14
+ pt = unpad(cipher.decrypt(ct), 16)
15
+
16
+ # AES-CBC
17
+ cipher = AES.new(key, AES.MODE_CBC, iv=iv)
18
+ ct = cipher.encrypt(pad(data, 16))
19
+ cipher2 = AES.new(key, AES.MODE_CBC, iv=iv)
20
+ pt = unpad(cipher2.decrypt(ct), 16)
21
+
22
+ # AES-CTR
23
+ cipher = AES.new(key, AES.MODE_CTR, nonce=nonce)
24
+ ct = cipher.encrypt(data) # no padding needed
25
+
26
+ # AES-GCM
27
+ cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
28
+ ct, tag = cipher.encrypt_and_digest(data)
29
+
30
+ RSA
31
+ from Crypto.PublicKey import RSA
32
+ from Crypto.Cipher import PKCS1_OAEP
33
+
34
+ # Generate key
35
+ key = RSA.generate(2048)
36
+ pub = key.publickey()
37
+
38
+ # Encrypt / Decrypt
39
+ cipher = PKCS1_OAEP.new(pub)
40
+ ct = cipher.encrypt(data)
41
+ cipher = PKCS1_OAEP.new(key)
42
+ pt = cipher.decrypt(ct)
43
+
44
+ # RSA math
45
+ key = RSA.import_key(open("key.pem").read())
46
+ n = key.n # modulus
47
+ e = key.e # public exponent
48
+ d = key.d # private exponent
49
+ p = key.p # prime 1
50
+ q = key.q # prime 2
51
+
52
+ # Textbook RSA
53
+ ct = pow(m, e, n) # encrypt
54
+ pt = pow(ct, d, n) # decrypt
55
+
56
+ HASHING
57
+ from Crypto.Hash import SHA256, MD5, SHA1
58
+
59
+ h = SHA256.new(data)
60
+ print(h.hexdigest())
61
+
62
+ h = MD5.new(data)
63
+ print(h.hexdigest())
64
+
65
+ RANDOM
66
+ from Crypto.Random import get_random_bytes
67
+ key = get_random_bytes(16) # 16 random bytes
68
+ iv = get_random_bytes(16)
69
+
70
+ USEFUL MATH
71
+ from Crypto.Util.number import *
72
+ long_to_bytes(n) Number → bytes
73
+ bytes_to_long(b) Bytes → number
74
+ getPrime(1024) Random 1024-bit prime
75
+ isPrime(n) Primality test
76
+ inverse(e, phi) Modular inverse
77
+ GCD(a, b) Greatest common divisor
@@ -0,0 +1,94 @@
1
+ Python 3 Quick Reference
2
+ ========================
3
+
4
+ DATA TYPES
5
+ x = 42 int
6
+ x = 3.14 float
7
+ s = "hello" str
8
+ b = b"\x41\x42" bytes
9
+ L = [1, 2, 3] list
10
+ T = (1, 2, 3) tuple
11
+ D = {"a": 1} dict
12
+ S = {1, 2, 3} set
13
+
14
+ STRINGS
15
+ s.upper() / s.lower() Case conversion
16
+ s.strip() Remove whitespace
17
+ s.split(",") Split to list
18
+ ",".join(L) Join list to string
19
+ s.replace("a", "b") Replace
20
+ s.startswith("he") Check prefix
21
+ s.encode() str → bytes
22
+ b.decode() bytes → str
23
+ f"Value: {x}" F-string formatting
24
+
25
+ BYTES & ENCODING
26
+ bytes.fromhex("4142") Hex string → bytes
27
+ b.hex() Bytes → hex string
28
+ import base64
29
+ base64.b64encode(b) Base64 encode
30
+ base64.b64decode(s) Base64 decode
31
+
32
+ LIST OPERATIONS
33
+ L.append(x) Add to end
34
+ L.extend([4,5]) Extend list
35
+ L.pop() Remove last
36
+ L[1:3] Slice
37
+ L[::-1] Reverse
38
+ sorted(L) Sort (new list)
39
+ [x*2 for x in L] List comprehension
40
+ len(L) Length
41
+
42
+ DICT OPERATIONS
43
+ D["key"] Get value
44
+ D.get("key", default) Get with default
45
+ D.keys() All keys
46
+ D.values() All values
47
+ D.items() Key-value pairs
48
+ {**D1, **D2} Merge dicts
49
+
50
+ FILE I/O
51
+ with open("f.txt") as f:
52
+ content = f.read()
53
+
54
+ with open("f.txt", "w") as f:
55
+ f.write("data")
56
+
57
+ with open("f.bin", "rb") as f:
58
+ data = f.read()
59
+
60
+ USEFUL MODULES
61
+ import os OS operations
62
+ import sys System-specific
63
+ import re Regular expressions
64
+ import json JSON parsing
65
+ import hashlib Hash functions
66
+ import struct Binary packing
67
+ import socket Network sockets
68
+ import subprocess Run commands
69
+ import itertools Iteration tools
70
+ import collections Specialized containers
71
+
72
+ COMMON PATTERNS
73
+ # Read binary file
74
+ data = open("file", "rb").read()
75
+
76
+ # Hex dump
77
+ print(data.hex())
78
+
79
+ # XOR bytes
80
+ result = bytes(a ^ b for a, b in zip(d1, d2))
81
+
82
+ # HTTP request
83
+ import requests
84
+ r = requests.get(url)
85
+ r = requests.post(url, data={"key": "val"})
86
+
87
+ # Run command
88
+ import subprocess
89
+ out = subprocess.check_output(["cmd", "arg"])
90
+
91
+ # Regex
92
+ import re
93
+ m = re.search(r"pattern", text)
94
+ matches = re.findall(r"pattern", text)
package/refs/r2.txt ADDED
@@ -0,0 +1,85 @@
1
+ Radare2 Quick Reference
2
+ =======================
3
+
4
+ STARTING
5
+ r2 binary Open binary
6
+ r2 -d binary Debug mode
7
+ r2 -A binary Auto-analyze on open
8
+ r2 -w binary Write mode
9
+
10
+ ANALYSIS
11
+ aaa Full analysis
12
+ afl List functions
13
+ afl~main Find main function
14
+ afn name addr Rename function
15
+ axt addr Cross-references to
16
+ axf addr Cross-references from
17
+
18
+ NAVIGATION
19
+ s main Seek to function
20
+ s 0x401000 Seek to address
21
+ s+10 / s-10 Seek forward/back
22
+
23
+ DISASSEMBLY
24
+ pd 20 Disassemble 20 instructions
25
+ pdf Disassemble current function
26
+ pdf @ main Disassemble main
27
+ pD 100 Disassemble 100 bytes
28
+
29
+ PRINT DATA
30
+ px 64 Hex dump 64 bytes
31
+ ps @ addr Print string
32
+ pf d @ addr Print as integer
33
+ p8 16 Print 16 hex bytes
34
+
35
+ VISUAL MODE
36
+ V Enter visual mode
37
+ VV Graph mode
38
+ p/P Cycle views in visual
39
+ q Quit visual
40
+
41
+ SEARCHING
42
+ / string Search for string
43
+ /x 90909090 Search hex pattern
44
+ /R pop rdi Search ROP gadget
45
+ iz List strings in data
46
+ izz List all strings
47
+
48
+ INFORMATION
49
+ i File info
50
+ ie Entry point
51
+ iS Sections
52
+ ii Imports
53
+ iE Exports
54
+ is Symbols
55
+ il Libraries
56
+
57
+ FLAGS / COMMENTS
58
+ f name @ addr Set flag (bookmark)
59
+ CC comment @ addr Add comment
60
+ CCu Remove comment
61
+
62
+ WRITE MODE (r2 -w)
63
+ wx 9090 @ addr Write hex bytes
64
+ wa "nop" @ addr Write assembly
65
+
66
+ DEBUG
67
+ db addr Breakpoint
68
+ dc Continue
69
+ ds Step
70
+ dr Show registers
71
+ dr rax=0 Set register
72
+
73
+ COMMON CTF PATTERNS
74
+ # Quick analysis
75
+ r2 -A binary
76
+ afl # list functions
77
+ s main # go to main
78
+ pdf # disassemble
79
+
80
+ # Find strings
81
+ iz~flag
82
+ iz~password
83
+
84
+ # Decompile (with r2ghidra)
85
+ pdg @ main # Ghidra decompiler output
package/refs/regex.txt ADDED
@@ -0,0 +1,73 @@
1
+ Regular Expressions Quick Reference
2
+ ====================================
3
+
4
+ BASIC PATTERNS
5
+ . Any character (except newline)
6
+ \d Digit [0-9]
7
+ \D Non-digit
8
+ \w Word character [a-zA-Z0-9_]
9
+ \W Non-word character
10
+ \s Whitespace
11
+ \S Non-whitespace
12
+ \b Word boundary
13
+
14
+ ANCHORS
15
+ ^ Start of string/line
16
+ $ End of string/line
17
+ \A Start of string only
18
+ \Z End of string only
19
+
20
+ QUANTIFIERS
21
+ * 0 or more
22
+ + 1 or more
23
+ ? 0 or 1
24
+ {n} Exactly n
25
+ {n,} n or more
26
+ {n,m} Between n and m
27
+ *? +? ?? Non-greedy versions
28
+
29
+ CHARACTER CLASSES
30
+ [abc] a, b, or c
31
+ [a-z] Lowercase letters
32
+ [A-Z] Uppercase letters
33
+ [0-9] Digits
34
+ [^abc] NOT a, b, or c
35
+ [a-zA-Z0-9] Alphanumeric
36
+
37
+ GROUPS & REFERENCES
38
+ (pattern) Capture group
39
+ (?:pattern) Non-capture group
40
+ (?P<name>pat) Named group (Python)
41
+ \1 Back-reference to group 1
42
+ (?=pattern) Lookahead
43
+ (?!pattern) Negative lookahead
44
+ (?<=pattern) Lookbehind
45
+ (?<!pattern) Negative lookbehind
46
+
47
+ ALTERNATION
48
+ a|b a or b
49
+ (cat|dog) cat or dog
50
+
51
+ COMMON CTF PATTERNS
52
+ # Flag format
53
+ icoa\{[^}]+\}
54
+
55
+ # IP address
56
+ \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
57
+
58
+ # Hex string
59
+ [0-9a-fA-F]+
60
+
61
+ # Base64
62
+ [A-Za-z0-9+/]+=*
63
+
64
+ # Email
65
+ [\w.+-]+@[\w-]+\.[\w.]+
66
+
67
+ # URL
68
+ https?://[^\s]+
69
+
70
+ GREP EXAMPLES
71
+ grep -E "icoa\{.*\}" file Find flags
72
+ grep -oP "\d+\.\d+\.\d+\.\d+" f Extract IPs
73
+ grep -rn "password" . Search recursively
@@ -0,0 +1,83 @@
1
+ Python Requests Quick Reference
2
+ ===============================
3
+
4
+ INSTALLATION
5
+ pip install requests
6
+
7
+ BASIC REQUESTS
8
+ import requests
9
+
10
+ r = requests.get(url)
11
+ r = requests.post(url, data={"key": "val"})
12
+ r = requests.put(url, json={"key": "val"})
13
+ r = requests.delete(url)
14
+ r = requests.head(url)
15
+ r = requests.options(url)
16
+
17
+ RESPONSE
18
+ r.status_code HTTP status code
19
+ r.text Response body (str)
20
+ r.content Response body (bytes)
21
+ r.json() Parse JSON response
22
+ r.headers Response headers
23
+ r.cookies Response cookies
24
+ r.url Final URL (after redirects)
25
+ r.elapsed Time elapsed
26
+ r.history Redirect history
27
+
28
+ PARAMETERS
29
+ # URL parameters
30
+ r = requests.get(url, params={"q": "search"})
31
+
32
+ # Headers
33
+ r = requests.get(url, headers={"Authorization": "Bearer tok"})
34
+
35
+ # Cookies
36
+ r = requests.get(url, cookies={"session": "abc"})
37
+
38
+ # POST data (form-encoded)
39
+ r = requests.post(url, data={"user": "admin"})
40
+
41
+ # POST JSON
42
+ r = requests.post(url, json={"user": "admin"})
43
+
44
+ # File upload
45
+ r = requests.post(url, files={"file": open("f", "rb")})
46
+
47
+ # Timeout
48
+ r = requests.get(url, timeout=5)
49
+
50
+ # Disable SSL verification
51
+ r = requests.get(url, verify=False)
52
+
53
+ # Follow redirects
54
+ r = requests.get(url, allow_redirects=False)
55
+
56
+ # Proxy
57
+ r = requests.get(url, proxies={"http": "http://127.0.0.1:8080"})
58
+
59
+ SESSIONS (persist cookies, headers)
60
+ s = requests.Session()
61
+ s.headers.update({"Authorization": "Bearer tok"})
62
+ s.get(url) # cookies persist
63
+ s.post(url, data=data) # same session
64
+
65
+ AUTH
66
+ from requests.auth import HTTPBasicAuth
67
+ r = requests.get(url, auth=HTTPBasicAuth("user", "pass"))
68
+ # shorthand:
69
+ r = requests.get(url, auth=("user", "pass"))
70
+
71
+ CTF PATTERNS
72
+ # SQL injection test
73
+ r = requests.get(url, params={"id": "1' OR '1'='1"})
74
+
75
+ # Cookie manipulation
76
+ r = requests.get(url, cookies={"admin": "true"})
77
+
78
+ # Brute force
79
+ for word in open("wordlist.txt"):
80
+ r = requests.post(url, data={"pass": word.strip()})
81
+ if "Success" in r.text:
82
+ print(f"Found: {word}")
83
+ break
package/refs/rules.txt ADDED
@@ -0,0 +1,28 @@
1
+ ICOA 2026 Competition Rules
2
+ ===========================
3
+
4
+ FORMAT
5
+ Jeopardy-style CTF
6
+ Categories: Crypto, Web, Pwn, Reverse, Forensics
7
+ Day 1: AI4CTF — Classic CTF with AI-assisted solving
8
+ Day 2: CTF4AI — Attacking AI models
9
+
10
+ HINT BUDGET
11
+ Level A (General Guidance): 50 uses
12
+ Level B (Deep Analysis): 10 uses
13
+ Level C (Critical Assist): 2 uses
14
+ Token Cap: 50,000 tokens
15
+
16
+ RULES
17
+ - All tools must run inside the Docker sandbox
18
+ - Flag format: icoa{...}
19
+ - No collaboration between teams during competition
20
+ - All AI prompts are logged and auditable
21
+ - Competition times are enforced server-side
22
+ - Submitting after competition ends is not allowed
23
+
24
+ SCORING
25
+ - Each challenge has fixed point value
26
+ - First-blood bonus may apply
27
+ - Final ranking by total score
28
+ - Ties broken by submission time
package/refs/scapy.txt ADDED
@@ -0,0 +1,80 @@
1
+ Scapy Quick Reference
2
+ =====================
3
+
4
+ INSTALLATION
5
+ pip install scapy
6
+
7
+ BASIC USAGE
8
+ from scapy.all import *
9
+
10
+ PACKET CREATION
11
+ # IP packet
12
+ pkt = IP(dst="10.0.0.1")
13
+
14
+ # TCP SYN
15
+ pkt = IP(dst="10.0.0.1")/TCP(dport=80, flags="S")
16
+
17
+ # UDP packet
18
+ pkt = IP(dst="10.0.0.1")/UDP(dport=53)/DNS()
19
+
20
+ # ICMP ping
21
+ pkt = IP(dst="10.0.0.1")/ICMP()
22
+
23
+ # HTTP request
24
+ pkt = IP(dst="10.0.0.1")/TCP(dport=80)/Raw(b"GET / HTTP/1.1\r\n\r\n")
25
+
26
+ SEND / RECEIVE
27
+ send(pkt) Layer 3 send (no response)
28
+ sr(pkt) Send and receive (layer 3)
29
+ sr1(pkt) Send and receive 1 packet
30
+ sendp(pkt) Layer 2 send
31
+ srp(pkt) Layer 2 send and receive
32
+
33
+ READING PCAP
34
+ pkts = rdpcap("capture.pcap")
35
+ pkts.summary()
36
+ pkts[0].show()
37
+
38
+ # Filter packets
39
+ tcp_pkts = [p for p in pkts if TCP in p]
40
+ http = [p for p in pkts if p.haslayer(Raw)]
41
+
42
+ # Extract data
43
+ for p in pkts:
44
+ if Raw in p:
45
+ print(p[Raw].load)
46
+
47
+ WRITING PCAP
48
+ wrpcap("output.pcap", pkts)
49
+
50
+ PACKET INSPECTION
51
+ pkt.show() Show packet details
52
+ pkt.summary() One-line summary
53
+ ls(TCP) List TCP fields
54
+ pkt[TCP].sport Access field
55
+ pkt.haslayer(TCP) Check layer exists
56
+ hexdump(pkt) Hex dump
57
+
58
+ SNIFFING
59
+ pkts = sniff(count=10)
60
+ pkts = sniff(filter="tcp port 80", count=10)
61
+ sniff(prn=lambda p: p.summary())
62
+
63
+ COMMON CTF PATTERNS
64
+ # Extract HTTP data from pcap
65
+ pkts = rdpcap("capture.pcap")
66
+ for p in pkts:
67
+ if TCP in p and Raw in p:
68
+ data = p[Raw].load
69
+ if b"flag" in data or b"icoa{" in data:
70
+ print(data)
71
+
72
+ # DNS exfiltration
73
+ dns_pkts = [p for p in pkts if DNS in p]
74
+ for p in dns_pkts:
75
+ if DNSQR in p:
76
+ print(p[DNSQR].qname)
77
+
78
+ # Reconstruct TCP stream
79
+ from scapy.layers.http import *
80
+ load_layer("http")