from django.shortcuts import render, redirect from django.http import HttpResponse import random from .forms import LoginForm, _2faForm import logging from base64 import b64decode import os
# Create your views here. defindex(request): return redirect(login)
#!/bin/python3 import sqlite3 import argparse import os
defprint_sql_content(database_file): os.system(f'if [ -f "{database_file}" ]; then echo "File exists: {database_file}";fi') try: conn = sqlite3.connect(database_file) cursor = conn.cursor() cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") tables = cursor.fetchall() for table in tables: table_name = table[0] print(f"Table: {table_name}") cursor.execute(f"SELECT * FROM {table_name};") rows = cursor.fetchall() for row in rows: print(row) conn.close() except sqlite3.Error as e: print("SQLite error:", e)
if __name__ == "__main__": parser = argparse.ArgumentParser(description="Print the content of an SQLite3 database file.") parser.add_argument("--sql", type=str, help="Path to the SQLite3 database file, usage: --sql=blog.sql", required=True) args = parser.parse_args() print_sql_content(args.sql)
import os f=open('wordlist.txt', 'r') wordlist=f.read().split('\n') for i in wordlist: text=os.popen(f'curl -i http://chals1.ais3.org:36743/dashboard/ --cookie "sessionid={i}"').read() if'/login/'notin text: print(text) print(i)
{ int local_14; __useconds_t local_10; printf( "What I\'m about to say. Old Man... Everyone... And you, Luffy... Even though... I\'m so wor thless... Even though... I carry the blood of a demon... Thank you... For loving me\nThe fla g is " ); local_10 = 2000000; usleep(2000000); for (local_14 = 0; (&DAT_0804a008)[local_14] != '\0'; local_14 = local_14 + 1) { usleep(local_10); printf("%c ",(int)(char)(&DAT_0804a008)[local_14]); fflush(stdout); local_10 = local_10 << 1; } usleep(local_10); puts("\n...uh, the rest, I\'ve forgotten it. Do you remember the rest of it?"); return; }
for i inrange(8): for j inrange(4): for k inrange(65, 91): if complex_function(k, i+j*32)==ord(ans[j][i]): flag[i+j*8]=k # print(xor(flag, 0)) # print(xor(flag, key)) print(b'AIS3{G0D'+xor(flag, key))
import random from Crypto.Util.number import getPrime from secret import flag defgcd(a, b): while b: a, b = b, a % b return a
defgenerate_keypair(keysize): p = getPrime(keysize) q = getPrime(keysize) n = p * q phi = (p-1) * (q-1) e = random.randrange(1, phi) g = gcd(e, phi) while g != 1: e = random.randrange(1, phi) g = gcd(e, phi) d = pow(e, -1, phi) return ((e, n), (d, n))
defencrypt(pk, plaintext): key, n = pk cipher = [pow(ord(char), key, n) for char in plaintext] return cipher
defdecrypt(pk, ciphertext): key, n = pk plain = [chr(pow(char, key, n)) for char in ciphertext] return''.join(plain)
e, n=(64917055846592305247490566318353366999709874684278480849508851204751189365198819392860386504785643859... table={} for i inrange(256): table[pow(i, e, n)]=i enc=[595829831363684348568167997333134467464337960343847242211744244649697378748021161293486079793280988417... flag='' for i in enc: flag+=chr(table[i]) print(flag)
#!/bin/python3 import random from Crypto.Util.number import getPrime, bytes_to_long, long_to_bytes from hashlib import sha256 from base64 import b64encode, b64decode from secret import flag import signal
defalarm(second): # This is just for timeout. # It should not do anything else with the challenge. defhandler(signum, frame): print('Timeout!') exit() signal.signal(signal.SIGALRM, handler) signal.alarm(second)
defgcd(a, b): while b: a, b = b, a % b return a
defgenerate_keypair(keysize): p = getPrime(keysize) q = getPrime(keysize) n = p * q phi = (p-1) * (q-1) e = random.randrange(1, phi) g = gcd(e, phi) while g != 1: e = random.randrange(1, phi) g = gcd(e, phi) d = pow(e, -1, phi) # for CRT optimize dP = d % (p-1) dQ = d % (q-1) qInvP = pow(q, -1, p) return ((e, n), (dP, dQ, qInvP, p, q))
defverify(pk, message: bytes, signature: bytes): e, n = pk data = bytes_to_long(sha256(message).digest()) return data == pow(bytes_to_long(signature), e, n)
bug = lambda : random.randrange(0, 256) defsign(sk, message: bytes): dP, dQ, qInvP, p, q = sk data = bytes_to_long(sha256(message).digest()) # use CRT optimize to sign the signature, # but there are bugs in my code QAQ a = bug() mP = pow(data, dP, p) ^ a b = bug() mQ = pow(data, dQ, q) ^ b k = (qInvP * (mP - mQ)) % p signature = mQ + k * q return long_to_bytes(signature)
if __name__ == "__main__": alarm(300)
public, private = generate_keypair(512) print(""" *********************************************************** Have you heard CRT optimization for RSA? I have implemented a CRT-RSA signature. However, there are bugs in my code... --------------------------------------------------------- 1) Print public key. 2) Sign a message. 3) Give me flag? 4) Bye~ *********************************************************** """)
for _ inrange(5): try: option = input("Option: ") ifint(option) == 1: print('My public key:') print(f"e, n = {public}")
elifint(option) == 2: message = input("Your message (In Base64 encoded): ") message = b64decode(message.encode()) ifb"flag"in message: print(f"No, I cannot give you the flag!") else: signature = sign(private, message) signature = b64encode(signature) print(f"Signature: {signature}") elifint(option) == 3: signature = input("Your signature (In Base64 encoded): ") signature = b64decode(signature.encode()) message = b64encode(b"Give me the flag!") if verify(public, message, signature): print(f"Well done! Here is your flag :{flag}") else : print("Invalid signature.")
defsign(sk, message: bytes): dP, dQ, qInvP, p, q = sk data = bytes_to_long(sha256(message).digest()) # use CRT optimize to sign the signature, # but there are bugs in my code QAQ a = bug() mP = pow(data, dP, p) ^ a b = bug() mQ = pow(data, dQ, q) ^ b k = (qInvP * (mP - mQ)) % p signature = mQ + k * q return long_to_bytes(signature)
from Crypto.Util.number import * from base64 import * from hashlib import sha256 import math n=int(input('n:')) e=int(input('e:')) c1=bytes_to_long(b64decode(input('c1:'))) c2=bytes_to_long(b64decode(input('c2:'))) diff=abs(c1-c2)
for i inrange(0, 256): if math.gcd(diff-i, n) > 1: q=math.gcd(diff-i, n) print('Found')
print(q) p=n//q phi=(p-1)*(q-1) d=inverse(e, phi) data=b64encode(b"Give me the flag!") data=bytes_to_long(sha256(data).digest()) data=long_to_bytes(pow(data, d, n)) print(b64encode(data))
#!/bin/python3 import random from secret import flag from Crypto.Util.number import bytes_to_long, getPrime, isPrime import signal
defalarm(second): # This is just for timeout. # It should not do anything else with the challenge. defhandler(signum, frame): print('Timeout!') exit() signal.signal(signal.SIGALRM, handler) signal.alarm(second)
defgen_prime(n): whileTrue: p = 1 while p < (1 << (n - 1)) : p *= getPrime(5) p = p * 2 + 1 if isPrime(p): break return p
defzkp_protocol(p, g, sk): # y = pow(g, sk, p) r = random.randrange(p-1) a = pow(g, r, p) print(f'a = {a}') print('Give me the challenge') try: c = int(input('c = ')) w = (c * sk + r) % (p-1) print(f'w = {w}') # you can verify I know the flag with # g^w (mod p) = (g^flag)^c * g^r (mod p) = y^c * a (mod p)
except: print('Invalid input.') if __name__ == "__main__": alarm(300) assertlen(flag) == 60 p = 912963562570713895762123712634341582363191342435924527885311975797578046400116904692505817547350929619596093083745446525856149291591598712142696114753807416455553636357128701771057485027781550780145668058332461392878693207262984011086549089459904749465167095482671894984474035487400352761994560452501497000487 # p is generated by gen_prime(1024) g = 5 y = pow(g, bytes_to_long(flag), p) print(""" ****************************************************** Have you heard of Zero Knowledge Proof? I cannot give you the flag, but I want to show you I know the flag. So, let me show you with ZKP. ------------------------------------------------------ 1) Printe public key. 2) Run ZKP protocol. 3) Bye~ ****************************************************** """)
可以看出來 p 是 smooth prime,結合$y=g^{ flag} (mod p)$,可以直接丟sage discrete_log解。 solve.sage
1 2 3 4 5 6 7 8 9 10 11 12
from Crypto.Util.number import * p = 912963562570713895762123712634341582363191342435924527885311975797578046400116904692505817547350929619596093083745446525856149291591598712142696114753807416455553636357128701771057485027781550780145668058332461392878693207262984011086549089459904749465167095482671894984474035487400352761994560452501497000487 g = 5 y = 826538666839613533825164219540577914201103248283631882579415248247469603672292332561005185045449294103457059566058782307774879654805356212117148864755019033392691510181464751398765490686084806155442759849410837406192708511190585484331707794669398717997173649869228717077858848442336016926370038781486833717341
defsolve_discrete_log(p, g, A): F = GF(p) g, A = F(g), F(A) a = discrete_log(A,g) return a