Board logo

标题: [系统相关] 病毒进程的网络连接ip怎么用批处理查出并用ipseccmd.exe创建ip策略阻止肉机与主机通信 [打印本页]

作者: 04235    时间: 2013-6-27 22:51     标题: 病毒进程的网络连接ip怎么用批处理查出并用ipseccmd.exe创建ip策略阻止肉机与主机通信

pid为3704的是病毒进程(abc.exe)

这是他的网络连接ip

这是ipseccmd的代码(阻止的协议是任意)
如何用批处理获取pid=3704(abc.exe)的网络连接ip
再用批处理把此进程abc.exe的网络连接ip写入ipseccmd代码拉的红线代码里(重点是用纯批处理 不手动编辑)
作者: apang    时间: 2013-6-28 11:26

这样吗?
  1. @echo off&setlocal enabledelayedexpansion
  2. >ok.bat echo ipseccmd -w REG -p "HFUT_SECU" -r "Block ICMP/255" -f *+0:255:ICMP -n BLOCK -x ^>nul
  3. >>ok.bat echo ipseccmd -w REG -p "HFUT_SECU" -r "Block TCP/43958" -f *+0:43958:TCP -n BLOCK -x ^>nul
  4. for /f "tokens=3" %%a in ('netstat -ao^|findstr "[^0-9]3704$"') do (
  5.    set "str=%%a"
  6.    if "!str:.=!" neq "!str!" (
  7.       for /f %%b in ("!str::= !") do (
  8.          >>ok.bat echo ipseccmd -w REG -p "clxp safe policy" -r "disable connect ip" -f 0/255.255.255.255=%%b/255.255.255.255:: -n BLOCK -x
  9.       )
  10.    )
  11. )
  12. pause
复制代码

作者: 04235    时间: 2013-6-30 03:51

回复 2# apang


    我把问题具体了下,大概意思就是用一个批处理来知道(abc.exe)进程的网络连接ip,再用ipseccmd阻止与其ip任何协议的通信,
希望能指教。
作者: apang    时间: 2013-6-30 05:47

回复 3# 04235


    你的意思是不生成ok.bat文件?对ipseccmd命令不熟悉,没有测试
  1. @echo off&setlocal enabledelayedexpansion
  2. ipseccmd -w REG -p "HFUT_SECU" -r "Block ICMP/255" -f *+0:255:ICMP -n BLOCK -x >nul
  3. ipseccmd -w REG -p "HFUT_SECU" -r "Block TCP/43958" -f *+0:43958:TCP -n BLOCK -x >nul
  4. for /f "tokens=3" %%a in ('netstat -ao^|findstr "[^0-9]3704$"') do (
  5.    set "str=%%a"
  6.    if "!str:.=!" neq "!str!" (
  7.       for /f %%b in ("!str::= !") do (
  8.          ipseccmd -w REG -p "clxp safe policy" -r "disable connect ip" -f 0/255.255.255.255=%%b/255.255.255.255:: -n BLOCK -x
  9.       )
  10.    )
  11. )
  12. pause
复制代码

作者: 04235    时间: 2013-6-30 06:20

本帖最后由 04235 于 2013-6-30 07:00 编辑

回复 4# apang


    刚测试了,两个都ok。能不能
  1. for /f "tokens=3" %%a in ('netstat -ao^|findstr "[^0-9]3704$"') do (
复制代码
中的3704改成进程,如abc.exe
回复 4# apang
作者: apang    时间: 2013-6-30 08:35

稍作修改应该就可以了
  1. @echo off&setlocal enabledelayedexpansion
  2. set "Name=abc.exe"
  3. ipseccmd -w REG -p "HFUT_SECU" -r "Block ICMP/255" -f *+0:255:ICMP -n BLOCK -x >nul
  4. ipseccmd -w REG -p "HFUT_SECU" -r "Block TCP/43958" -f *+0:43958:TCP -n BLOCK -x >nul
  5. set "wmic=wmic process where "name='%Name%'" get processid"
  6. for /f %%a in ('%wmic%^|findstr "^[0-9]"') do set "pid=!pid! [^^0-9]%%a$"
  7. for /f "tokens=3" %%a in ('netstat -ao^|findstr "%pid:~1%"') do (
  8.    set "str=%%a"
  9.    if "!str:.=!" neq "!str!" (
  10.       for /f %%b in ("!str::= !") do (
  11.          ipseccmd -w REG -p "clxp safe policy" -r "disable connect ip" -f 0/255.255.255.255=%%b/255.255.255.255:: -n BLOCK -x
  12.       )
  13.    )
  14. )
  15. pause
复制代码

作者: wskwfkbdn    时间: 2013-7-18 07:36

回复 1# 04235
    你都知道是病毒进程了,为啥不杀掉,却是阻止网络连接,难道你是养马的,啥逻辑思维,难以理解,
作者: wskwfkbdn    时间: 2013-7-18 07:37

把进程一结束,然后删除,不更省事了,也没了后顾之忧,




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2