不知名CTF比赛的不知名题目,类井字棋,要写程序判断。
写了两个程序:如下:
C++有漏洞,够用就行:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include<iostream> #include<algorithm> using namespace std; int process[10] = { 4 }; bool visited[10]; inline int cal(int x, int y) { return x * 3 + y; } bool& vis(int x, int y) { return visited[cal(x, y)]; } bool check(int x, int y) { bool flag = false; flag |= vis(0, y) & vis(1, y) & vis(2, y); flag |= vis(x, 0) & vis(x, 1) & vis(x, 2); if (x == y)flag |= vis(0, 0) & vis(1, 1) & vis(2, 2); if (x + y == 2)flag |= vis(0, 2) & vis(1, 1) & vis(2, 0); return flag; } void print(int n) { for (int i = 0; i <= n; i++) { cout << process[i]; } cout << endl; } void dfs(int step) { bool flag = true; for (int i = 0; i < 9; i++) { if (visited[i])continue; visited[i] = true; process[step] = i; if (check(i / 3, i % 3) == 0) { dfs(step + 1); flag = false; } visited[i] = false; } if (flag&&step%2==1)print(step); } int main() { visited[4] = true; dfs(1); } |
python连带着往外发socket麻烦得很:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | from pwn import * sock = remote("222.186.56.247",8122) wordList = [] currentWord = "" def findNewWord(): global currentWord,wordList for elem in wordList: if elem[0:len(currentWord)]==currentWord: return elem raise Exception("Error:Word Not found!") def loadDic(): global wordList with open("situation.txt","r") as f: wordList = f.readlines() def getIntfromSock(sock): sock.recvuntil("My move: ") x = sock.recv(1) if x==b' ': x = sock.recv(1) return int(x) def payGame(i): global currentWord,wordList,sock print("the ith:",i) currentWord="" while len(currentWord) < 5: backupWord = findNewWord() print("Send:",backupWord[len(currentWord)]) sock.sendline(str(backupWord[len(currentWord)])) currentWord += backupWord[len(currentWord)] if len(currentWord)==5: print("break") break currentWord += str(getIntfromSock(sock)) print("currentWord",currentWord) sock.recvuntil("win!") loadDic() for i in range(150): payGame(i) sock.interactive() |
代码链接:notakto