The cryptography category is incomplete without RSA. So here is a simple RSA challenge. Have fun!
1 2 3
e = 3 n = 135112325288715136727832177735512070625083219670480717841817583343851445454356579794543601926517886432778754079508684454122465776544049537510760149616899986522216930847357907483054348419798542025184280105958211364798924985051999921354369017984140216806642244876998054533895072842602131552047667500910960834243 c = 13037717184940851534440408074902031173938827302834506159512256813794613267487160058287930781080450199371859916605839773796744179698270340378901298046506802163106509143441799583051647999737073025726173300915916758770511497524353491642840238968166849681827669150543335788616727518429916536945395813
解题:
rsa 低指数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from gmpy2 import iroot import libnum
e = 3 n = 135112325288715136727832177735512070625083219670480717841817583343851445454356579794543601926517886432778754079508684454122465776544049537510760149616899986522216930847357907483054348419798542025184280105958211364798924985051999921354369017984140216806642244876998054533895072842602131552047667500910960834243 c = 13037717184940851534440408074902031173938827302834506159512256813794613267487160058287930781080450199371859916605839773796744179698270340378901298046506802163106509143441799583051647999737073025726173300915916758770511497524353491642840238968166849681827669150543335788616727518429916536945395813
k = 0 while1: res = iroot(c + k * n, e) # c+k*n 开3次方根 能开3次方即可 if (res[1] == True): print(libnum.n2s(int(res[0]))) # 转为字符串 break k = k + 1 # b'n00bz{crypt0_1s_1nc0mpl3t3_w1th0ut_rs4!!}'
alphanumerical = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(){}_?' matrix = [] for i in alphanumerical: matrix.append([i])
idx=0 for i in alphanumerical: matrix[idx][0] = (alphanumerical[idx:len(alphanumerical)]+alphanumerical[0:idx]) idx += 1
flag=open('../src/flag.txt').read().strip() key='5up3r_s3cr3t_k3y_f0r_1337h4x0rs_r1gh7?' assertlen(key)==len(flag) flag_arr = [] key_arr = [] enc_arr=[] for y in flag: for i inrange(len(alphanumerical)): if matrix[i][0][0]==y: flag_arr.append(i)
for y in key: for i inrange(len(alphanumerical)): if matrix[i][0][0]==y: key_arr.append(i)
for i inrange(len(flag)): enc_arr.append(matrix[flag_arr[i]][0][key_arr[i]]) encrypted=''.join(enc_arr) f = open('enc.txt','w') f.write(encrypted)
alphanumerical = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(){}_?' matrix = [] for i in alphanumerical: matrix.append([i])
idx = 0 for i in alphanumerical: matrix[idx][0] = (alphanumerical[idx:len(alphanumerical)] + alphanumerical[0:idx]) idx += 1
boolamazingcustomsortingalgorithm(string s){ int n = s.size(); for (int i = 0; i < 69; i++) { cout << s << endl; bool good = true; for (int i = 0; i < n - 1; i++) good &= s[i] <= s[i + 1];
map<char, int> counts; for (char c : s) { if (counts[c]) { cout << "no repeating letters allowed passed this machine" << endl; return1; } counts[c]++; }
if (s.size() < 10) { cout << "this machine will only process worthy strings" << endl; return1; }
if (s.size() == 69) { cout << "a very worthy string" << endl; cout << "i'll give you a clue'" << endl; cout << "just because something says it's random mean it actually is" << endl; return69; }
random_shuffle(s.begin(), s.end());
if (amazingcustomsortingalgorithm(s)) { ifstream fin("flag.txt"); string flag; fin >> flag; cout << flag << endl; } else { cout << "UNWORTHY USER DETECTED" << endl; } }
import subprocess from base64 import b64decode as d whileTrue: print("[1] Write to a file\n[2] Get the flag\n[3] Exit") try: inp = int(input("Choice: ").strip()) except: print("Invalid input!") exit(0) if inp == 1: file = input("Enter file name: ").strip() assert file.count('.') <= 2# Why do you need more? assert"/proc"notin file # Why do you need to write there? assert"/bin"notin file # Why do you need to write there? assert"\n"notin file # Why do you need these? assert"chall"notin file # Don't be overwriting my files! try: f = open(file,'w') except: print("Error! Maybe the file does not exist?")
f.write(input("Data: ").strip()) f.close() print("Data written sucessfully!")
if inp == 2: flag = subprocess.run(["cat","fake_flag.txt"],capture_output=True) # You actually thought I would give the flag? print(flag.stdout.strip())
#!/usr/bin/env python3 from flask import Flask, request, redirect, render_template, render_template_string import subprocess import urllib import uuid global leet
app = Flask(__name__) flag = open('/flag.txt').read() leet=uuid.UUID('13371337-1337-1337-1337-133713371337')
@app.route('/',methods=['GET','POST']) defmain(): global username if request.method == 'GET': return render_template('index.html') elif request.method == 'POST': username = request.values['username'] if username == 'admin123': return'Stop trying to act like you are the admin!' uid = uuid.uuid5(leet,username) # super secure! return redirect(f'/{uid}')
@app.route('/<uid>') defuser_page(uid): if uid != str(uuid.uuid5(leet,'admin123')): returnf'Welcome! No flag for you :(' else: return flag
if __name__ == '__main__': app.run(host='0.0.0.0', port=1337)
elif command == ',': if input_pointer < len(input_data): tape[pointer] = ord(input_data[input_pointer]) input_pointer += 1 else: tape[pointer] = 0# If no input is available, set cell to 0
Why did the macros hide its knowledge? Because it didn’t want anyone to “excel”! Note: char_21 is the SAME as char_22 Note 2: The correct flag has ALL LOWERCASE, NUMBERS, n00bz{} AND UNDERSCORES (There’s two underscores in the entire flag)