先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip204888 (备注网络安全)
正文
def continued_fraction(sub_res):
numerator, denominator = 1, 0
for i in sub_res[::-1]: # 从sublist的后面往前循环
denominator, numerator = numerator, i * numerator + denominator
return denominator, numerator # 得到渐进分数的分母和分子,并返回
求解每个渐进分数
def sub_fraction(x, y):
res = transform(x, y)
res = list(map(continued_fraction, (res[0:i] for i in range(1, len(res))))) # 将连分数的结果逐一截取以求渐进分数
return res
def get_pq(a, b, c): # 由p+q和pq的值通过维达定理来求解p和q
par = gmpy2.isqrt(b * b - 4 * a * c) # 由上述可得,开根号一定是整数,因为有解
x1, x2 = (-b + par) // (2 * a), (-b - par) // (2 * a)
return x1, x2
def wienerAttack(e, n):
for (d, k) in sub_fraction(e, n): # 用一个for循环来注意试探e/n的连续函数的渐进分数,直到找到一个满足条件的渐进分数
if k == 0: # 可能会出现连分数的第一个为0的情况,排除
continue
if (e * d - 1) % k != 0: # ed=1 (mod φ(n)) 因此如果找到了d的话,(ed-1)会整除φ(n),也就是存在k使得(e*d-1)//k=φ(n)
continue
phi = (e * d - 1) // k # 这个结果就是 φ(n)
px, qy = get_pq(1, n - phi + 1, n)
if px * qy == n:
p, q = abs(int(px)), abs(int(qy)) # 可能会得到两个负数,负负得正未尝不会出现
d = gmpy2.invert(e, (p - 1) * (q - 1)) # 求ed=1 (mod φ(n))的结果,也就是e关于 φ(n)的乘法逆元d
return d
print("该方法不适用")
n = 6969872410035233098344189258766624225446081814953480897731644163180991292913719910322241873463164232700368119465476508174863062276659958418657253738005689
e = 3331016607237504021038095412236348385663413736904453330557803644384818257225138777641344877202234881627514102078530507171735156112302207979925588113589669
c = 1754994938947260364311041300467524420957926989584983693004487724099773647229373820465164193428679197813476633649362998772470084452129370353136199193923837
d = wienerAttack(e, n)
m=pow(c, d, n)
print(long_to_bytes(m))
得到答案:*b'NSSCTF{e\_is\_so\_huge}'*
#### p5.py
题目:
from Crypto.Util.number import *
import os
flag = os.getenv(‘FLAG’)
m = bytes_to_long(flag.encode())
e = 127
def enc():
p = getPrime(512)
q = getPrime(512)
n = p*q
c = pow(m, e, n)
print(f"n: {n}“)
print(f"c: {c}”)
def main():
while True:
opt = int(input('input> '))
if opt == 1:
enc()
main()
>
> os.getenv(key, default = None)函数:用于获取环境变量的值,返回的是字符串
>
>
> * key:表示的是环境变量名称的字符串
> * default (可写可不写):表示 key 不存在时默认值的字符串。如果省略,则默认设置为“无”。
>
>
> **环境变量**是存储在操作系统环境中的键值对,其是影响运行在系统上的进程行为集合的变量。
>
>
>
>
> encode()函数:编码函数,使用指定编码格式对字符串进行编码,缺省编码格式为“utf-8”
>
>
>
题目有点问题,跳过
#### p6.py
题目:
from Crypto.Util.number import *
from random import choice
flag = b’NSSCTF{******}’
def getMyPrime(nbits):
while True:
p = 1
while p.bit_length() <= nbits:
p *= choice(sieve_base)
#choice()用于在一个列表中随机选择一个数,sieve_base是一个包含素数的元组
if isPrime(p+1):
return p+1
#如果p+1是素数则返回,否则再次循环,随机选择数
p = getMyPrime(256)
q = getMyPrime(256)
n = p*q
e = 65537
m = bytes_to_long(flag)
c = pow(m, e, n)
print(f’n = {n}‘)
print(f’e = {e}’)
print(f’c = {c}')
‘’’
n = 53763529836257082401813045869248978487210852880716446938539970599235060144454914000042178896730979463959004404421520555831136502171902051936080825853063287829
e = 65537
c = 50368170865606429432907125510556310647510431461588875539696416879298699197677994843344925466156992948241894107250131926237473102312181031875514294014181272618
‘’’
>
> **1.random模块中的choice()函数用于在一个序列(列表,元组或字符串中随机选择一个元素并返回**
>
>
> **2.sieve\_base是由前10000的素数组成的列表,里面最大的数是104729,是在Crypto.Util.number中**
>
>
>
那么现在的问题就是如何分解n,使用工具果然分不开,好吧不会了,搜索了一下(搜索引擎是强大的),看了一下网上的wp
这是一道**p-1光滑题**
>
> **光滑数:**一个数n可以被分解为若干**小质数**的乘积,则称n为光滑数。
>
>
> **B-Smooth数****:**若一个光滑数中最大的质数因子 <= B, 则称其为B-Smooth数。
>
>
> 即 n = ![p_{1}p_{2}...p_{n},p_{n}\leq b](https://latex.csdn.net/eq?p_%7B1%7Dp_%7B2%7D...p_%7Bn%7D%2Cp_%7Bn%7D%5Cleq%20b),则称n是b−Smooth数
>
>
> (p1,p2,……,pn两两互不相同)
>
>
>
利用的是费马小定理:
>
> **若b为一个素数,则任意一个与b互质的整数a,有a^(b-1) mod b ≡ 1**
>
>
> **拓展结论:a ^k(b-1) mod b ≡1(k为正整数)**
>
>
> **推导:**
>
>
> a ^k(b-1) mod b
>
>
> =(a^(b-1) )^k mod b
>
>
> =(a^(b-1) mod b \* a^(b-1) mod b \*……\*a^(b-1) mod b) mod b
>
>
> 总共k个
>
>
> =1
>
>
>
那么对于这道题:
(p-1)和(q-1)都是sieve\_base列表中若干个素数的乘积,即**(p-1)和(q-1)均为光滑数**
那么p-1=p1\*p2\*....\*pn
设有一个B,使其满足p-1=p1\*p2\*....\*pn,pn<=B,则**p-1是B-Smooth数**
>
> 由质因数分解的原理:任何一个正整数N都可以表示为质数因子的乘积,即因数分解的意思
>
>
>
有:**B!**=1\*2\*3\*..\*p1.....\*pn\*...=k\*p1\*p2\*...\*pn=**k\*(p-1)**
那么由费马定理有:a ^ k\*(p-1)≡1 mod p 即 a ^ B! =1 mod p 即 a ^ B! -1≡ k\*p
那么很显然 a ^ B! - 1 是 p 的倍数
因为n= p \* q ,那么很显然n也是p的倍数
则gcd(2 ^ B! - 1 , n) = p,就可以求到p
而B!是不知道的,于是递推计算
解密代码:
from Crypto.Util.number import *
from gmpy2 import *
from bytes import *
n = 53763529836257082401813045869248978487210852880716446938539970599235060144454914000042178896730979463959004404421520555831136502171902051936080825853063287829
e = 65537
c = 50368170865606429432907125510556310647510431461588875539696416879298699197677994843344925466156992948241894107250131926237473102312181031875514294014181272618
def Pollards_p_1(N):
a = 2 # 为了快速计算以及满足费马小定理条件
n = 2 # 从1开始没必要
while (True):
a = pow(a, n, N) # 递推计算a^B!
p = gcd(a - 1, N) # 尝试计算p
if p != 1 and p != N: # 满足要求则返回
# print(n)
return p
n += 1
p=Pollards_p_1(n)
q=n//p
phi=(p-1)*(q-1)
d=invert(e,phi)
m=powmod(c,d,n)
print(long_to_bytes(m))
得到答案:*b'NSSCTF{p-1\_smooth\_with\_factor}'*
参考博客(这三篇博客都写的很详细,大佬好厉害,前两篇不是一个题型,但是可以看一下,一开始搞错了,没看清楚┭┮﹏┭┮):
[BUUCTF\_Crypto题目题解记录1\_buuctf crypto-CSDN博客]( )
[BUUCTF [NCTF2019]childRSA(费马小定理)-CSDN博客]( )-CSDN博客")
[RSA攻击:Smooth攻击-CSDN博客]( )
#### p7.py
题目:
from Crypto.Util.number import *
from random import choice
flag = b’NSSCTF{******}’
def getMyPrime(nbits):
while True:
p = 1
while p.bit_length() <= nbits:
p *= choice(sieve_base)
if isPrime(p-1):
return p-1
p = getMyPrime(256)
q = getMyPrime(256)
n = p*q
e = 65537
m = bytes_to_long(flag)
c = pow(m, e, n)
print(f’n = {n}‘)
print(f’e = {e}’)
print(f’c = {c}')
‘’’
n = 63398538193562720708999492397588489035970399414238113344990243900620729661046648078623873637152448697806039260616826648343172207246183989202073562200879290937
e = 65537
c = 26971181342240802276810747395669930355754928952080329914687241779532014305320191048439959934699795162709365987652696472998140484810728817991804469778237933925
‘’’
这道题和上一题很像,这是一道**p+1平滑题** (累了,等我下次来解吧)
解密代码:
得到答案:
#### p8.py
题目:
n = 120294155186626082670474649118722298040433501930335450479777638508444129059776534554344361441717048531505985491664356283524886091709370969857047470362547600390987665105196367975719516115980157839088766927450099353377496192206005171597109864609567336679138620134544004766539483664270351472198486955623315909571
e1 = 38317
e2 = 63409
c1 = 42703138696187395030337205860503270214353151588149506110731264952595193757235229215067638858431493587093612397165407221394174690263691095324298012134779703041752810028935711214038835584823385108771901216441784673199846041109074467177891680923593206326788523158180637665813642688824593788192044139055552031622
c2 = 50460092786111470408945316270086812807230253234809303694007902628924057713984397041141665125615735752600114964852157684904429928771531639899496987905067366415806771003121954852465731110629459725994454904159277228514337278105207721011579794604761255522391446534458815389983562890631994726687526070228315925638
这题有两个e,两个c,想到共模攻击,直接解密即可
解密代码:
from Crypto.Util.number import *
from gmpy2 import *
n = 120294155186626082670474649118722298040433501930335450479777638508444129059776534554344361441717048531505985491664356283524886091709370969857047470362547600390987665105196367975719516115980157839088766927450099353377496192206005171597109864609567336679138620134544004766539483664270351472198486955623315909571
e1 = 38317
e2 = 63409
c1 = 42703138696187395030337205860503270214353151588149506110731264952595193757235229215067638858431493587093612397165407221394174690263691095324298012134779703041752810028935711214038835584823385108771901216441784673199846041109074467177891680923593206326788523158180637665813642688824593788192044139055552031622
c2 = 50460092786111470408945316270086812807230253234809303694007902628924057713984397041141665125615735752600114964852157684904429928771531639899496987905067366415806771003121954852465731110629459725994454904159277228514337278105207721011579794604761255522391446534458815389983562890631994726687526070228315925638
(s,s1,s2)=gcdext(e1,e2)
mt=pow(c1,s1,n)*pow(c2,s2,n)
ms=pow(mt,1,n)
m=iroot(ms,s)[0]
print(long_to_bytes(m))
得到答案:*b'NSSCTF{same\_module\_attack!}'*
#### p9.py
题目:
p = 13070310882303377463944295715444821218324151935347454554272870042925400761984585838979931730897626589859098834802923539617244712852188293321626061072925723
q = 10411551818233737389114520103233235272671271111546186997024935593000298916988792710521511848414549553426943998093077337023514210631662189798921671306236009
c = 62492280219693914005334023569480350249964827909276875032578276064973191654731196407886841145547165693859745313398152742796887457192397932684370631253099255490064673499746314452067588181106154875239985334051909867580794242253066085627399488604907196244465911471895118443199543361883148941963668551684228132814
dp = 11568639544706374912496682299967972464196129347160700749666263275305083977187758414725188926013198988871173614336707804756059951725809300386252339177953017
dq = 3455040841431633020487528316853620383411361966784138992524801280785753201070735373348570840039176552952269927122259706586236960440300255065994052962742469
有dp和dq,那么根据(推导后面补上):
>
> m1≡c^dq mod q
> m2≡c^dp mod p
> m≡(((m2−m1)\*p−1 mod q)p+m1) mod n
>
>
>
即可求解
解密代码:
from Crypto.Util.number import *
import gmpy2
import libnum
p = 13070310882303377463944295715444821218324151935347454554272870042925400761984585838979931730897626589859098834802923539617244712852188293321626061072925723
q = 10411551818233737389114520103233235272671271111546186997024935593000298916988792710521511848414549553426943998093077337023514210631662189798921671306236009
c = 62492280219693914005334023569480350249964827909276875032578276064973191654731196407886841145547165693859745313398152742796887457192397932684370631253099255490064673499746314452067588181106154875239985334051909867580794242253066085627399488604907196244465911471895118443199543361883148941963668551684228132814
dp = 11568639544706374912496682299967972464196129347160700749666263275305083977187758414725188926013198988871173614336707804756059951725809300386252339177953017
dq = 3455040841431633020487528316853620383411361966784138992524801280785753201070735373348570840039176552952269927122259706586236960440300255065994052962742469
m1=pow(c,dp,p)
m2=pow(c,dq,q)
p_q=inverse(p,q)
m=(m1+(p_q*(m2-m1)%qp))%(pq)
print(long_to_bytes(m))
得到答案:*b'NSSCTF{dp&dq\_leak}'*
#### p10.py
题目:
n = 79201858340517902370077926747686673001645933420450220163567700296597652438275339093680329918615445030212417351430952656177171126427547284822789947152085534939195866096891005587613262293569611913019639653984932469691636338705418303482885987114085769045348074530172292982433373154900841135911548332400167290083
c = 70109332985937768446301118795636999352761371683181615470371772202170324747707233792154935611826981798791499937601162039878070094663516868746240133223110650205575807753345252087103328657073552992431511929172241702073381723302143955977662087561904058172777520360991685289300855900793806183473523998422682944404
dp = 3098334089252415941833934532457314870210700261428241562420857845879512952043729097866485406309479489101668423603305497982177150304625615059119312238777275
e = 65537
根据题目,应该是dp泄露,对应写出解密代码即可
解密代码:
### 给大家的福利
**零基础入门**
对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。
![](https://img-blog.csdnimg.cn/img_convert/95608e9062782d28f4f04f821405d99a.png)
同时每个成长路线对应的板块都有配套的视频提供:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/a91b9e8100834e9291cfcf1695d8cd42.png#pic_center)
因篇幅有限,仅展示部分资料
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注网络安全)**
![img](https://img-blog.csdnimg.cn/img_convert/4bfacd565aa97baaa993922eae337830.png)
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
路线,大家跟着这个大的方向学习准没问题。
![](https://img-blog.csdnimg.cn/img_convert/95608e9062782d28f4f04f821405d99a.png)
同时每个成长路线对应的板块都有配套的视频提供:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/a91b9e8100834e9291cfcf1695d8cd42.png#pic_center)
因篇幅有限,仅展示部分资料
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注网络安全)**
[外链图片转存中...(img-4PuIKGtW-1713310242830)]
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**