文件上传漏洞常见绕过手法
0x00 一般防止上传漏洞手法
1、客户端检测:客户端使用JavaScript检测,在文件未上传时,就对文件进行验证
//任何客户端的验证都是不安全的,客户端验证目的是防止用户输入错误、减少
//服务器开销,而服务端验证才可以真正防御攻击者。
2、服务器端检测:服务端脚本一般会检测文件的MIME类型,检测文件扩展名是否合法
0x01 客户端检测
客户端验证代码形如下:
more...1、客户端检测:客户端使用JavaScript检测,在文件未上传时,就对文件进行验证
//任何客户端的验证都是不安全的,客户端验证目的是防止用户输入错误、减少
//服务器开销,而服务端验证才可以真正防御攻击者。
2、服务器端检测:服务端脚本一般会检测文件的MIME类型,检测文件扩展名是否合法
客户端验证代码形如下:
more...当文件上传时,若服务端脚本语言未对上传的文件进行严格验证和过滤,若恶意用户上传恶意的
脚本文件时,就有可能控制整个网站甚至是服务器,这就是文件上传漏洞。
# 上传后得到的权限
1. 后台权限:登陆了后台,可以进行一些操作、配置
2. 网站权限:获得了webshell,可以进行查看源代码等操作
3. 服务器权限:可以对服务器进行任意操作
1. 配置不当可直接上传shell
HTTP的PUT方法开启了
2. 文件解析漏洞导致文件执行
Web容器解析漏洞
3. 本地文件上传限制被绕过
BurpSuite抓包修改即可绕过
4. 服务端过滤不严或被绕过
使用了黑名单过滤
5. 文件路径截断上传
00截断等
6. 开源编辑器上传漏洞
如CKEditor(FCKeditor的新版)、eWebEditor的漏洞
1. 首先,上传的文件能够被web容器解释执行。所以文件上传后的目录要是web容器所覆盖到的路径
2. 其次,用户能从web访问这个文件
3. 最后,用户上传的文件若被安全检查、格式化、图片压缩等功能改变了内容,则可能导致攻击失败
1. 查找上传点,如图片、附件、头像的上传等
2. 找类似upload的目录、类似upload.php的文件
3. 找编辑器目录,如eWebEdirot、fckeditor、kingeditor等
可用于绕过:
php php2 php3 php5 phtml
asp aspx ascx ashx cer asa
jsp jspx jspf
文件上传漏洞通常与Web容器的解析漏洞配合利用
常见Web容器有IIS、Nginx、Apache、Tomcat等
IIS6.0在解析文件时存在以下两个解析漏洞
more...XSS(跨站脚本攻击)是指攻击者在网页中嵌入客户端脚本,通常是Javascript编写的恶意代码,当用户使用浏览器浏览被嵌入恶意代码的网页时,恶意代码将在用户的浏览器上被解析执行。重点在"脚本"这两个字上,脚本主要有两个:JavaScript和ActionScript。
直接pip install paramiko安装
或者去http://www.paramiko.org/ 下载
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import paramiko
#远程执行命令
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.188.134",22,"reber","123456")
ssh_session = ssh.get_transport().open_session()
stdin,stdout,stderr = ssh.exec_command("ls -l")
print stdin
print stdout.readlines() #返回执行结果
print stderr.readlines() #有错误信息就返回错误信息,没有就返回空
ssh.close()
使用cmd模块创建的命令行解释器可以循环读取输入的所有行并且解析它们
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import os
import socket
from cmd import Cmd
class ClassShell(Cmd):
"""docstring for ClassShell"""
def __init__(self):
Cmd.__init__(self)
os.chdir("C:/Users/reber/Desktop")
hostName = socket.gethostname()
self.prompt = "reber@" + hostName + " " + os.path.abspath('.') + "\n$ "
def help_dir(self):
print "dir [path]"
def do_dir(self, arg):
if not arg:
print "\n".join(os.listdir('.'))
elif os.path.exists(arg):
print "\n".join(os.listdir(arg))
else:
print "no such path exists"
def help_ls(self):
print "ls [path]"
def do_ls(self, arg):
if not arg:
print "\n".join(os.listdir('.'))
elif os.path.exists(arg):
print "\n".join(os.listdir(arg))
else:
print "no such path exists"
def help_pwd(self):
print "pwd"
def do_pwd(self, arg):
print os.path.abspath('.')
def help_cd(self):
print "cd [path]"
def do_cd(self, arg):
hostName = socket.gethostname()
if not arg:
os.chdir("C:/Users/reber/Desktop")
self.prompt = "reber@" + hostName + " " + os.path.abspath('.') + "\n$ "
elif os.path.exists(arg):
os.chdir(arg)
self.prompt = "reber@" + hostName + " " + os.path.abspath('.') + "\n$ "
else:
print "no such path"
def help_clear(self):
print "clear"
def do_clear(self, arg):
i = os.system('cls')
def help_cat(self):
print "cat filename"
def do_cat(self, arg):
if os.path.exists(arg):
with open(arg,"r") as f:
data = f.read()
print data
else:
print "no such file exists"
def help_mv(self):
print "mv oldfilename newfilename"
def do_mv(self, arg):
oldfilename,newfilename = arg.split()
if os.path.exists(oldfilename):
os.rename(oldfilename,newfilename)
else:
print "no such file:" + oldfilename
def help_touch(self):
print "touch filename"
def do_touch(self, arg):
with open(arg, "w") as f:
pass
def help_rm(self):
print "rm filepath"
def do_rm(self, arg):
if os.path.exists(arg):
os.remove(arg)
else:
print "no such file:" + arg
def help_cp(self):
print "cp oldfilepath newfilepath"
def do_cp(self, arg):
oldfilepath,newfilepath = arg.split()
if os.path.exists(oldfilepath):
with open(oldfilepath, "r") as f:
data = f.read()
with open(newfilepath, "w") as f:
f.write(data)
else:
print "no such path:" + oldfilepath
def help_exit(self):
print "input exit will exit the program"
def do_exit(self, arg):
print "Exit:",arg
sys.exit()
if __name__ == '__main__':
shell = ClassShell()
shell.cmdloop()
前提:攻击主机和被攻击主机在一个无线下面
在软件的图形化界面点击sniff,选择unified sniffing选择网卡,然后单击hosts选项,选择scan for host,然后选择host list