Skip to content

Instantly share code, notes, and snippets.

@ITAYC0HEN
Last active September 12, 2016 06:56
Show Gist options
  • Save ITAYC0HEN/b2292df63d7956585d6fbda2ab834a25 to your computer and use it in GitHub Desktop.
Save ITAYC0HEN/b2292df63d7956585d6fbda2ab834a25 to your computer and use it in GitHub Desktop.
[ASIS-CTF] SecuPrim
from pwn import *
from hashlib import *
import string
import itertools
from Crypto.Util.number import *
from sympy import perfect_power
import time
# Cout primes and perfect powers in a range
def countNumbers(lower,upper):
countp= 0
countpp=0
num=lower
while num <= upper:
if isPrime(num):
countp+=1
if perfect_power(num):
countpp+=1
num+=1
return countpp+countp
# Connect to the server using pwntools
conn = remote('secuprim.asis-ctf.ir',42738)
print conn.recvline(timeout=2)
print conn.recvline(timeout=2)
res = conn.recvline(timeout=2)
print res
print conn.recvline(timeout=2)
postfix = res.split('"')[1]
sha = res.split('"')[3][:8]
alphanumeric = string.uppercase+string.lowercase+string.digits
ans =""
# Find X
for s in itertools.product(alphanumeric,repeat=4):
if sha256("%s%s"%(''.join(s),postfix)).hexdigest().startswith(sha):
print ''.join(s)
ans=s
break;
ans= ''.join(ans)
conn.send(ans)
count=0
print conn.recvline()
print conn.recvline()
# Solve the tests
while True:
time.sleep(1)
print conn.recvline()
count+=1
print "Question number: %d"%count
numbers = conn.recvline()
print numbers
num1=long(numbers.split()[12])
num2=long(numbers.split()[16])
answer=str(countNumbers(num1,num2))
conn.send(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment