Last active
May 18, 2020 16:46
-
-
Save hyp3rflow/dc7f1217fd4b678e4639fe946f813177 to your computer and use it in GitHub Desktop.
COSE213 Assignment_05 Tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
201R COSE213 Assignment_05 Tester | |
writer: hyperflow@kakao.com | |
to avoid Unicode problem, | |
$ export PYTHONIOENCODING=UTF-8 | |
사용하기 위해서는 다음과 같은 수정이 필요합니다. | |
1. 우분투 환경에서 실행되도록 해주세요. (Ubuntu 18.04.3 LTS x64) | |
2. 같은 디렉토리에 ./intbst (해답 파일)과 ./randtest.o (확인하고자 하는 파일)이 준비되어 있어야 합니다. | |
3. ./randtest.o는 확인하고자 하는 c 코드에 srand(time(NULL));을 빼고, 제일 첫 입력을 추가하여 받은 값을 랜덤시드에 넣어주세요. | |
4. 디렉토리로 이동한 후 코드를 실행하면 됩니다. | |
''' | |
from pwn import * | |
from ctypes import * | |
from filecmp import cmp | |
import random | |
import sys | |
matchcnt = 0 | |
epochsize = 50 | |
for _ in range(epochsize): | |
number = 30 | |
output_1 = open("./output1.txt", "w") | |
output_2 = open("./output2.txt", "w") | |
input_list = [] | |
random.shuffle(input_list) | |
c = CDLL("/lib/x86_64-linux-gnu/libc.so.6") | |
p = process("./intbst", stdout=output_1) | |
t = process("./intbst") | |
t.sendline(str(number)) | |
p.sendline(str(number)) | |
randkey = c.time(0) | |
result = str(t.recvline()) | |
t.close() | |
result = result.split() | |
for i in result: | |
if i.isdigit(): | |
input_list.append(int(i)) | |
for i in range(random.randint(0, 10)): | |
input_list.append(random.randint(0, number*3)) | |
random.shuffle(input_list) | |
for i in input_list: | |
p.sendline(str(i)) | |
sleep(5) | |
p.close() | |
output_1.close() | |
t = process("./randtest.o", stdout=output_2) | |
t.sendline(str(randkey)) | |
t.sendline(str(number)) | |
for i in input_list: | |
t.sendline(str(i)) | |
sleep(5) | |
t.close() | |
output_2.close() | |
if cmp('./output1.txt', './output2.txt'): | |
matchcnt += 1 | |
print("\n" + "=" * 30 + "\n") | |
print(f"\n\tMatching! {matchcnt} / {epochsize}\n") | |
print("\n" + "=" * 30 + "\n") | |
else: | |
print("\n$ Doesn't Matching!\n") | |
break | |
print(f"\n\tepoch evaluation complete, {matchcnt} / {epochsize}\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment