[pwnable.kr]coin1

在这里插入图片描述


        ---------------------------------------------------
        -              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                      # counterfeit coin is third!
        [Server] Correct!

        - Ready? starting in 3 sec... -


用二分法写个脚本

from pwn import *


r = remote('pwnable.kr',9007)

rec=r.recvuntil('- Ready? starting in 3 sec... -\n',drop=False)


r.recvline()

for i in range(100):

    t=r.recvline().decode('utf-8').split(' ')
    n=int(t[0].split('=')[1])
    c=int(t[1].split('=')[1])
    print('N=',n,'C=',c)

    start = 0
    end = n - 1
    print('start=',start,'end=',end)

    for j in range(c):

        mid = ( start + end )// 2
        print('mid=',mid)

        s=' '.join(str(k) for k in range(start,mid + 1))
        r.sendline(s)
        #print('send the index:',s)

        tmp_res=r.recvline()
        #print(tmp_res)

        if (int(tmp_res) % 10 == 0):
            start = mid + 1
        else:
            end = mid
    r.sendline(str(start))
    print(r.recvline())

print(r.recvline())
print(r.recvline())

如果远程连接的话因为网络延迟的问题会超时
在这里插入图片描述

需要连接到之前的其他题目给的ssh
然后mkdir /tmp/叫什么都行
在新建的文件夹里面写脚本
回过头来发现每次连接的时候的提示里面就有说到写权限目录的问题,
在这里插入图片描述

有个没太搞懂的点,在于pwntools和python版本的关系,
在我自己的虚拟机上面pwntools需要python3才能跑,
在靶机上面反而是python2才行

from pwn import *


r = remote('localhost',9007)

rec=r.recvuntil('- Ready? starting in 3 sec... -\n',drop=False)


r.recvline()

for i in range(100):

    t=r.recvline().decode('utf-8').split(' ')
    n=int(t[0].split('=')[1])
    c=int(t[1].split('=')[1])
    #print('N=',n,'C=',c)

    start = 0
    end = n - 1
    #print('start=',start,'end=',end)

    for j in range(c):
		#把这一层循环里的print全部注释掉似乎会快一点
		#虽然本来也不需要print
		
        mid = ( start + end )// 2
        #print('mid=',mid)

        s=' '.join(str(k) for k in range(start,mid + 1))
        r.sendline(s)
        #print('send the index:',s)

        tmp_res=r.recvline()
        #print(tmp_res)

        if (int(tmp_res) % 10 == 0):
            start = mid + 1
        else:
            end = mid
    r.sendline(str(start))
    print(r.recvline())

print(r.recvline())
print(r.recvline())

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值