NSSCTF Round#17 Basic CRYPTO
Level_1
题目
Level_1.py(我把参数整理了一下,看着舒服)
#真签到题
from Crypto.Util.number import bytes_to_long, getPrime
from secret import getflag
p = getPrime(1024)
q = getPrime(1024)
n = p * q
m = bytes_to_long(getflag().encode())
c1 = pow(m, p, n)
c2 = pow(m, q, n)
print(n)
print(c1)
print(c2)
print(p)
print(q)
# n = 22517647586235353449147432825948355885962082318127038138351524894369583539246623545565501496312996556897362735789505076324197072008392656511657262430676945685471397862981216472634785622155317188784494912316440866051402627470561626691472280850273482836308002341429493460677206562201947000047718275995355772707947408688836667011206588727438261189233517003341094758634490421007907582147392858070623641389171229435187248184443645883661560636995548332475573072064240073037558031928639832259001407585962782698021735648128101459118863015844905452823095147248865104102562991382119836061161756978764495337874807458182581421229
# c1 = 1432393096266401187029059077791766305797845826173887492889260179348416733820890797101745501984437201566364579129066414005659742104885321270122634155922766503333859812540068278962999824043206496595825886026095484801291802992082454776271149083516187121160475839108002133113254134626407840182541809478892306748590016896975053434021666376203540725254480252049443975835307793528287818262102688334515632062552114342619781840154202525919769192765621085008206581226486157149883898548933475155236509073675387541466324512294079413938239828341890576923100769181401944289365386552139418728492565319685207500539721582552448971814
# c2 = 13299679392897297864252207869444022461237574801991239380909482153705185317634241850084078027230394830079554676426505967970943836811048777462696506309466535820372917756458083553031417406403895116557560548183674144457502601887632495739472178857537011190162283185735114683172731936834993707871636782206418680404006299140864001776588991141011500807549645227520128216130966268810165946959810884593793452437010902774726405217517557763322690215690606067996057037379898630878638483268362526985225092000670251641184960698506349245915816808028210142606700394584541282682338561482561343076218115042099753144875658666459825545602
# p = 155861690390761931560700906834977917646203451142415617638229284868013723431003139974975998354830978765979365632120896717380895021936387027045347260400512396388028781862427862974453223157509702913026222541667006325100878113871620322023188372501930117363623076837619478555007555970810681502521309925774889678793
# q = 144471983652821947847253052623701746810204736865723159569786739658583884214397562204788127484897909964898113250509653721265240138487697822089282456150238116811225975640330930854549232972314642221382625614304415750165289831040623741828600283778523993251940904896081111235859249916040849697146542311990869696453
secret.py
def getflag():
return 'NSSCTF{Y0u_want_what!!!}'
我的解答:
签到题,真的是签到嘿嘿嘿,看很多师傅用的共模攻击,其实也不用,都是对同一旗帜进行的加密,我们用一组即可。
比如我们看第一组,这里的加密指数e其实就是p,我们可知p,q,n,e,c都已知,直接梭即可
exp:
import gmpy2
from Crypto.Util.number import *
p = 155861690390761931560700906834977917646203451142415617638229284868013723431003139974975998354830978765979365632120896717380895021936387027045347260400512396388028781862427862974453223157509702913026222541667006325100878113871620322023188372501930117363623076837619478555007555970810681502521309925774889678793
q = 144471983652821947847253052623701746810204736865723159569786739658583884214397562204788127484897909964898113250509653721265240138487697822089282456150238116811225975640330930854549232972314642221382625614304415750165289831040623741828600283778523993251940904896081111235859249916040849697146542311990869696453
n = 22517647586235353449147432825948355885962082318127038138351524894369583539246623545565501496312996556897362735789505076324197072008392656511657262430676945685471397862981216472634785622155317188784494912316440866051402627470561626691472280850273482836308002341429493460677206562201947000047718275995355772707947408688836667011206588727438261189233517003341094758634490421007907582147392858070623641389171229435187248184443645883661560636995548332475573072064240073037558031928639832259001407585962782698021735648128101459118863015844905452823095147248865104102562991382119836061161756978764495337874807458182581421229
c1 = 1432393096266401187029059077791766305797845826173887492889260179348416733820890797101745501984437201566364579129066414005659742104885321270122634155922766503333859812540068278962999824043206496595825886026095484801291802992082454776271149083516187121160475839108002133113254134626407840182541809478892306748590016896975053434021666376203540725254480252049443975835307793528287818262102688334515632062552114342619781840154202525919769192765621085008206581226486157149883898548933475155236509073675387541466324512294079413938239828341890576923100769181401944289365386552139418728492565319685207500539721582552448971814
phi = (p-1)*(q-1)
d = gmpy2.invert(p,phi)
m = pow(c1,d,n)
print(long_to_bytes(m))
#NSSCTF{Y0u_Hav3_S01v3d_Crypt0_Leve1_i}
Level_2
题目
hint:e is a common e
Level_2.py
# 猜猜我是谁 猜对了直接秒出flag喔
from Crypto.Util.number import bytes_to_long, getPrime
from secret import getflag
p = ***
q = getPrime(1024)
e = you guess!
n = p * q
m = bytes_to_long(getflag().encode())
c=pow(m, e, n)
print(q)
print(c)
#p=one of ps
#q=145721736470529261146573065574028992352505611489859183763269215489708531333597694809923949026781460438320576519639268582565188719134157402292313959218961804213310847081787824780075530751842057663327444602428455144829447776271394663729996984613471623158126083062443634493708467568220146024273763894704649472957
#c=17441814714407189483380175736850663249578989775568187792928771544069162420510939242665830363276698262009780462912108642025299275146709817979705069095332726251759039923303627023610865046363171692163473939115438686877494878334016463787558794121885354719336139401336137097548305393030069499625065664884238710759260231321106291200849044147840392021931720902340003746946851806025722944795391356835342258387797980787437188976704677008092850181043891802072500430200735973581081228711070923822341261809453662427341958883142789220800541626034573952425948295446202775198692920613709157662831071515700549093766182579873408465779
#flag=NSSCTF{*}
secret.py
def getflag():
return 'NSSCTF{You_Open_Me_Again!!!}'
ps.txt(内容太多这里就不写完了)
112570061288378069698095973797005529770680093845875223894997231628336829949265892727685350018077594566290824268610648959971872907584202027357045022857069974808762471714819971890294050173438079696242727451386551493649076611880968665058995978923502888694810161303133554247010154982747490401927615698764244575641
160390345706816858928712766237430683880617356868344036698358703998333407749759520169301916333739046480408394559790599973541103169787850665278836627642898619297749297488964496319606975452596625244508217477776522963045377479261162883238162733599875452839053545655376526116053288991549884653357989658618517105739
135274466561036154078983088599958139019086085585949467588985205105812446898435696006770477951085211474194015652753723608465972758093765295013977480077536663462359246172027648236195047543583386559597971108147534622182729246605513241519170365324169846986609310875122877897274699603690766660965072311242257844683
138911436184035411312080317190170788684424368688033129106939678172112294080712687220545748826015533434613777107494802659423833111286512824438806541791135385865106570037291005668611521376293259246116906155604890821875736413366752183442187739338638604045391231977875571324580145808190681511754014953150411573749
109003763690498543195236746159436380771897695450387210983374093441017415764628099371078873895655589281703285655726042956360681700927592983338522453278912601255567126713963945252430830834993483396585689829542246058662932613423243445885667303835965706012503101194446739723698993285990913911596033955033953763147
.......
我的解答:
签到升级版,还是签到。。根据提示可知e=65537
还说了p是ps.txt文件内容里的其中一个,q,c,e已知,我们只需要遍历p就可以了。
exp1:
from Crypto.Util.number import *
import gmpy2
# 从文件中读取可能的p值
with open("ps.txt", "r") as file:
p_values = file.readlines()
# 遍历每个 p 值
for p_str in p_values:
p = int(p_str.strip()) #记得转换类型
q = 145721736470529261146573065574028992352505611489859183763269215489708531333597694809923949026781460438320576519639268582565188719134157402292313959218961804213310847081787824780075530751842057663327444602428455144829447776271394663729996984613471623158126083062443634493708467568220146024273763894704649472957
c = 17441814714407189483380175736850663249578989775568187792928771544069162420510939242665830363276698262009780462912108642025299275146709817979705069095332726251759039923303627023610865046363171692163473939115438686877494878334016463787558794121885354719336139401336137097548305393030069499625065664884238710759260231321106291200849044147840392021931720902340003746946851806025722944795391356835342258387797980787437188976704677008092850181043891802072500430200735973581081228711070923822341261809453662427341958883142789220800541626034573952425948295446202775198692920613709157662831071515700549093766182579873408465779
n = p * q
e = 65537
phi = (p - 1) * (q - 1)
d = gmpy2.invert(e,phi)
m = pow(c, d, n)
flag = long_to_bytes(m).decode('latin1')
if "NSS" in flag:
print(flag)
#NSSCTF{Y0u_g0t_1t!!!}
当然还有一种方法,反正是猜嘛那就猜测flag不太长,直接在模q下解即可
exp2:
import gmpy2
from Crypto.Util.number import *
q=145721736470529261146573065574028992352505611489859183763269215489708531333597694809923949026781460438320576519639268582565188719134157402292313959218961804213310847081787824780075530751842057663327444602428455144829447776271394663729996984613471623158126083062443634493708467568220146024273763894704649472957
c= 17441814714407189483380175736850663249578989775568187792928771544069162420510939242665830363276698262009780462912108642025299275146709817979705069095332726251759039923303627023610865046363171692163473939115438686877494878334016463787558794121885354719336139401336137097548305393030069499625065664884238710759260231321106291200849044147840392021931720902340003746946851806025722944795391356835342258387797980787437188976704677008092850181043891802072500430200735973581081228711070923822341261809453662427341958883142789220800541626034573952425948295446202775198692920613709157662831071515700549093766182579873408465779
e = 65537
d = gmpy2.invert(e, q-1)
m = pow(c, d, q)
print(long_to_bytes(m))
#NSSCTF{Y0u_g0t_1t!!!}
Level_3
题目
自动化RSA?

我的解答:
题目给了一张图片,发现要拿到flag要进行665次
先连接靶机看看是啥情况。

试了一下是共模攻击(共n),也就是说本题是一个共模攻击交互题。那就好办了,写交互就行了。
exp:
from Crypto.Util.number import *
import gmpy2
from pwn import *
from tqdm import *
def decode(n,e1,e2,c1,c2):
t = gmpy2.gcd(e1,e2)
if t == 1:
s,x,y = gmpy2.gcdext(e1,e2)
m = (pow(c1,x,n)*pow(c2,y,n))%n
flag = long_to_bytes(m)
return flag
else:
s,x,y = gmpy2.gcdext(e1,e2)
k = 0
while 1:
m = gmpy2.iroot((pow(c1,x,n)*pow(c2,y,n)+k*n)%n,t)
if m[1]:
print(long_to_bytes(m[0]))
break
else:
k += 1
sh = remote("IP",端口号)
#这里需要666次,试了试665次打不出来
for i in trange(666):
data = sh.recvuntil(b" y0u J01n In th3 NSS t3am?\n py?\n")
n = eval(sh.recvline().decode().strip().split("=")[-1])
e1 = eval(sh.recvline().decode().strip().split("=")[-1])
e2 = eval(sh.recvline().decode().strip().split("=")[-1])
c1 = eval(sh.recvline().decode().strip().split("=")[-1])
c2 = eval(sh.recvline().decode().strip().split("=")[-1])
flag = decode(n,e1,e2,c1,c2)
sh.sendlineafter(b"[+] Pl Give Me flaag :",flag)
sh.interactive()
NSSCTF Round#17 Basic CRYPTO的更多相关文章
- CH Round #17 舞动的夜晚
舞动的夜晚 CH Round #17 描述 L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的 ...
- “玲珑杯”线上赛 Round #17 河南专场
闲来无事呆在寝室打打题,没有想到还有中奖这种操作,超开心的 玲珑杯”线上赛 Round #17 河南专场 Start Time:2017-06-24 12:00:00 End Time:2017-06 ...
- Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...
- Educational Codeforces Round 17
Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...
- Codeforces Global Round 17
Codeforces Global Round 17 A. Anti Light's Cell Guessing 坑点:\(n=1,m=1\) 时答案为 \(0\) . 其他情况:当 \(n=1\) ...
- [题解]Codeforces Round #709 (Div. 1, based on Technocup 2021 Final Round) - A. Basic Diplomacy
[题目] A. Basic Diplomacy [描述] Aleksey有n个朋友,有一个m天的假期,每天都需要一个朋友来陪他.给出每天有空的朋友的编号,要求同一个朋友来的天数不能超过m/2上取整.求 ...
- Codeforces Beta Round #17 C. Balance DP
C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes ...
- Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...
- hdu 5101 Select(Bestcoder Round #17)
Select Time Limit: 4000/2000 MS (Java/Others) ...
- [Educational Round 17][Codeforces 762F. Tree nesting]
题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...
随机推荐
- Java 日志框架学习笔记
日志概念 1. 日志文件 日志文件是用于记录系统操作事件的文件集合 1.1 调试日志 1.2 系统日志 系统日志是记录系统中硬件.软件和系统问题的信息,同时还可以监视系统中发生的事件.用户可以通过它来 ...
- Lambda 表达式各种用法,你都会了吗
公众号「架构成长指南」,专注于生产实践.云原生.分布式系统.大数据技术分享. 前言 Lambda表达式是 Java 8 中引入的最有影响力的功能之一.它们通过允许简洁而优雅地创建匿名函数来实现 Jav ...
- Tomcat--多实例
配置信息 centos:7.8 tomcat:7.0.3 instans1:/usr/local/tomcat/instans1 8081 instans2:/usr/local/tomcat/ins ...
- 灵魂拷问std::enable_shared_from_this,揭秘实现原理
参考博客: std::enable_shared_from_this原理浅析 引言 在C++编程中,使用智能指针是一种安全管理对象生命周期的方式.std::shared_ptr是一种允许多个指针共享对 ...
- HDU - 2897 邂逅明下 (简单博弈)
题目链接: https://vjudge.net/problem/HDU-2897 题目大意: 就是现在一堆石子有n颗, 每次只能拿走p~q颗, 当剩余少于p颗的时候必须一次拿完 拿走最后一颗的人败 ...
- 硬核调试实操 | 手把手带你实现 Serverless 断点调试
导读:在应用开发过程中,或者开发完成后,若出现执行结果不符合我们的预期时,通常需要进行一定的调试工作.但是在 Serverless 架构下,调试工作往往会受到一些环境因素限制,如所开发的应用在本地是比 ...
- <vue 路由 8、keep-alive的使用>
一. 知识点 1.什么是keep-alive? keep-alive是Vue.js的一个内置组件. 包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们.它自身不会渲染一个 DOM 元素,也 ...
- linux挂载磁盘和设置开机自动挂载
1.查看分区信息 root@xmgl opt]# fdisk -l ......此处省略一些信息 Disk /dev/sdb: 644.2 GB, 644245094400 bytes, 125829 ...
- Jstack 查看线程状态及定位占用 cpu 较高的 java 线程
本文为博主原创,未经允许不得转载: 1. Jstack 用来查看 java 指定进程所包含的 java 线程状态: "arthas-NettyHttpTelnetBootstrap-3 ...
- AMBA总线介绍-02
AMBA总线介绍 1 HSIZE AHB总线的地址位宽和数据位宽一般都是32bit,一个字节8bit,一个字节占用一个地址空间,但当一个32bit的数据写入一个存储器中或者从一个存储器中读取,32bi ...