Mommy, I wanna play a game!
(if your network response time is too slow, try nc 0 9007 inside pwnable.kr server)
Running at : nc pwnable.kr 9007
import re
from socket import *
def getIndex(inv):
mylist = []
for i in range(inv[0],inv[1]):
mylist.append(str(i))
return ' '.join(mylist)
HOST = '0'
PORT = 9007
ADDR = (HOST,PORT)
BUFSIZE = 1024
socketClient = socket(AF_INET,SOCK_STREAM)
socketClient.connect(ADDR)
data = socketClient.recv(BUFSIZE)
print(data)
data = socketClient.recv(BUFSIZE)
print(data)
startPattern = re.compile(r'^N=(\d*)\sC=(\d*)$')
Pattern_10 = re.compile(r'^(\d*0)$')
Pattern_9 = re.compile(r'^(\d*9)$')
curIds = None
preIds = None
while True:
data = socketClient.recv(BUFSIZE)
print data
match1 = startPattern.match(data)
match2 = Pattern_10.match(data)
match3 = Pattern_9.match(data)
if match1:
preIds = (0,int(match1.group(1)))
curIds = (preIds[0],(preIds[0] + preIds[1]) / 2 + (preIds[0]+preIds[1]) % 2)
socketClient.send(getIndex((curIds[0],curIds[1])) + '\r\n')
print getIndex((curIds[0],curIds[1]))
elif match2:
preIds = (curIds[1],preIds[1])
curIds = (preIds[0],(preIds[0] + preIds[1]) / 2 + (preIds[0]+preIds[1]) % 2)
socketClient.send(getIndex((curIds[0],curIds[1])) + '\r\n')
print getIndex((curIds[0], curIds[1]))
elif match3:
preIds = curIds
curIds = (preIds[0],(preIds[0] + preIds[1]) / 2 + (preIds[0]+preIds[1]) % 2)
socketClient.send(getIndex((curIds[0],curIds[1])) + '\r\n')
print getIndex((curIds[0], curIds[1]))
elif 'wrong' in data or 'error' in data or 'bye' in data:
break
socketClient.close()
acat@acat-xx:~$ ssh shellshock@pwnable.kr -p2222
shellshock@pwnable.kr's password:
____ __ __ ____ ____ ____ _ ___ __ _ ____
| \| |__| || \ / || \ | | / _] | |/ ]| \
| o ) | | || _ || o || o )| | / [_ | ' / | D )
| _/| | | || | || || || |___ | _] | \ | /
| | | ` ' || | || _ || O || || [_ __ | \| \
| | \ / | | || | || || || || || . || . \
|__| \_/\_/ |__|__||__|__||_____||_____||_____||__||__|\_||__|\_|
- Site admin : daehee87@gatech.edu
- IRC : irc.netgarage.org:6667 / #pwnable.kr
- Simply type "irssi" command to join IRC now
- files under /tmp can be erased anytime. make your directory under /tmp
- to use peda, issue `source /usr/share/peda/peda.py` in gdb terminal
You have new mail.
Last login: Sun Feb 9 02:02:53 2020 from 58.243.250.247
shellshock@pwnable:~$ cd /tmp
shellshock@pwnable:/tmp$ vi a.py
shellshock@pwnable:/tmp$ python a.py
---------------------------------------------------
- Shall we play a game? -
---------------------------------------------------
You have given some gold coins in your hand
however, there is one counterfeit coin among them
counterfeit coin looks exactly same as real coin
however, its weight is different from real one
real coin weighs 10, counterfeit coin weighes 9
help me to find the counterfeit coin with a scale
if you find 100 counterfeit coins, you will get reward :)
FYI, you have 60 seconds.
- How to play -
1. you get a number of coins (N) and number of chances (C)
2. then you specify a set of index numbers of coins to be weighed
3. you get the weight information
4. 2~3 repeats C time, then you give the answer
- Example -
[Server] N=4 C=2 # find counterfeit among 4 coins with 2 trial
[Client] 0 1 # weigh first and second coin
[Server] 20 # scale result : 20
[Client] 3 # weigh fourth coin
[Server] 10 # scale result : 10
[Client] 2 # coun
terfeit coin is third!
[Server] Correct!
- Ready? starting in 3 sec... -
N=401 C=9
0 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
2010
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
1000
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
500
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
249
351 352 353 354 355 356 357 358 359 360 361 362 363
129
351 352 353 354 355 356 357
69
351 352 353 354
39
351 352
20
353
9
353
Correct! (0)
N=979 C=10
....................................
136 137 138 139 140 141 142 143 144 145 146 147
120
148 149 150 151 152 153
59
148 149 150
29
148 149
19
148
10
149
Correct! (99)
Congrats! get your flag
b1NaRy_S34rch1nG_1s_3asy_p3asy
time expired! bye!
shellshock@pwnable:/tmp$