Last active
April 14, 2018 18:35
-
-
Save intrd/cc86849addec85cdcc1642d71c4b5976 to your computer and use it in GitHub Desktop.
Encoding solution - prog300 @ hackaflag 2017 - joao pessoa
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
#!/usr/bin/python | |
## Encoding solution - prog300 @ hackaflag 2017 - joao pessoa | |
# @author intrd - http://dann.com.br/ + pwn4food team | |
# int_netcat.py: https://gist.github.com/intrd/00a39c83f752acf81775bfa9721e745a | |
import re, sys, string, math, time, os, random | |
sys.path.append("../../LIBS") | |
from int_netcat import Netcat | |
def chunks(line): | |
n = 2 | |
return [line[i:i+n] for i in range(0, len(line), n)] | |
def get_pairs(myarray): | |
pairs=list() | |
for i in range(len(myarray)): | |
pair=(myarray*2)[i:i+2] | |
pairs.append(pair) | |
del pairs[-1] | |
return pairs | |
def partitions(s, k): | |
if not k: | |
yield [s] | |
return | |
for i in range(len(s) + 1): | |
for tail in partitions(s[i:], k - 1): | |
yield [s[:i]] + tail | |
def all_same(items): | |
return all(x == items[0] for x in items) | |
def vai(S): | |
xxx = partitions(S, 10) | |
filtered=[] | |
for x in xxx: | |
x = list(filter(lambda x: x!= "", x)) | |
#x = list(filter(lambda x: x!= "00", x)) | |
#x = list(filter(lambda x: int(x)<= 25, x)) | |
#x = list(filter(lambda x: x[0]!= "0", x)) | |
if len(x)>=1: | |
filtered.append(x) | |
#print x | |
# for f in filtered: | |
# print f | |
# exit() | |
aaa=[] | |
for x in filtered: | |
add=True | |
for xx in x: | |
if int(xx)>25: add=False | |
if int(xx)==0 and all_same(x): add=False | |
if add: | |
aaa.append(x) | |
#print aaa | |
#exit() | |
xxxx=[] | |
for x in aaa: | |
add = True | |
if len(x)==1 and x[0][0]=="0": add = False | |
if add: xxxx.append(x) | |
xxx=[] | |
for x in xxxx: | |
if x not in xxx: | |
xxx.append(x) | |
xxxx=[] | |
for x in xxx: | |
add = True | |
for w in x: | |
if len(w)>1 and w[0]=="0": add=False | |
if add: xxxx.append(x) | |
# pr = get_pairs(S) | |
# for p in pr: | |
# if int(p)<=25 and p not in xxxx: | |
# xxxx.append(p) | |
#exit() | |
if list(S) not in xxxx: xxxx.append(list(S)) | |
for f in xxxx: | |
print f | |
#if len(S)>2 and len(xxx)==1: return 2 | |
#if len(xxxx)==0: return 1 | |
return len(xxxx) | |
# print vai("01511") | |
# exit() | |
# print vai("25623") | |
#print vai("812731") | |
#exit() | |
nc = Netcat('104.236.245.201', 11718) | |
data=nc.read_until_prompt() | |
nc.write("start") | |
data=nc.read() | |
print(data) | |
while 1: | |
data=nc.read_until("N:") | |
print(data) | |
#exit() | |
if "HACKA" in data: | |
with open("FLAG","a") as f: | |
f.write(data) | |
sys.exit() | |
if "Saindo" in data: | |
with open("buff","a") as f: | |
#f.write(N+":"+str(int(A)-1)+"\n") | |
f.write(N+":"+str(int(A))+"\n") | |
break | |
N = nc.read_until("\n").strip() | |
#print N | |
#exit() | |
#A = solve(str(N)) | |
A = vai(str(N)) | |
# with open("buff","r") as f: | |
# for n in f: | |
# if N in n: | |
# A=n.split(":")[1].strip() | |
# #print A | |
# #exit() | |
print A | |
nc.write(str(A)+"\n") | |
#exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment