2

我发现了一个系统上的 0-day Java 漏洞利用,它让我想到了在每个用户配置文件中查看 Java .idx 文件以查找可能指向活动 0-day 威胁的可疑 URL。

我从这个开始:

for /d %%A in ("C:\Documents and Settings\*") do (
findstr /S "http://" "%%A\Application Data\Sun\Java\Deployment\cache\6.0\*" >> C:\temp\javaurls.txt)

这会生成一个完整的 URL 文件,但它们与大量控制信息和其他无趣的东西混在一起。我想做的是为每个找到的“http://”小写实例创建一个换行符。任何人都知道如何在批处理文件中使用命令行来做到这一点?

4

2 回答 2

0

我知道“只需使用其他工具!” 答案可能很烦人。但是,Windows 批处理文件/命令行实用程序非常糟糕,我认为如果您必须经常做这类事情,那么值得研究其他选项。除非您喜欢找出未记录的、非标准的、损坏的正则表达式并且即使是最基本的功能也需要 hacky 解决方案,也就是说。

一些选项:

  • Perl
  • 适用于 Windows的 Grep(与 findstr 等效得多)
  • Cygwin(用于 Windows 的整个类似于 Linux 的 shell 环境;包括 grep)。

这是您可以添加到批处理文件中的单行 Perl 以在每个之前添加换行符http://

perl -pi.bak -e "s|(http://)|\n$1|g" C:\temp\javaurls.txt

但是,如果我从头开始,我会在 Perl 中完成整个事情,而不是使用批处理文件。

于 2012-12-18T15:12:27.733 回答
0

我一般同意其他人表达的观点 - 批处理在处理文本方面很糟糕。使用另一种语言或工具对您的任务来说是一个好主意。

但它可以用批处理来完成:-)

简单地在每个之前插入一个换行符html://并不难

@echo off
setlocal disableDelayedExpansion
:: The first FOR loop loads a quoted linefeed into %%L
:: The blank line within the IN() clause is critical. Do not remove.
for %%L in (^"^

^") do (
  for /d %%A in ("C:\Documents and Settings\*") do (
    for /f "eol=: delims=" %%B in (
      'findstr /S "http://" "%%A\Application Data\Sun\Java\Deployment\cache\6.0\*"'
    ) do (
      set "line=%%B"
      setlocal enableDelayedExpansion
      echo(!line:http://=%%~Lhttp://!
      endlocal
    )
  )
) >c:\temp\javaurls.txt

但是只保留以开头的结果行,http://并在地址成为真正的痛苦之前保留每个文件的名称。

@echo off
setlocal disableDelayedExpansion
:: The first FOR loop loads a quoted linefeed into %%L
:: The blank line within the IN() clause is critical. Do not remove.
for %%L in (^"^

^") do (
  for /d %%A in ("C:\Documents and Settings\*") do (
    for /f "tokens=1* delims=:" %%B in (
      'findstr /S "http://" "%%A\Application Data\Sun\Java\Deployment\cache\6.0\*"'
    ) do (
      set "line=%%C"
      setlocal enableDelayedExpansion
      set "line=!line:http://=%%~Lhttp://!"
      for /f "delims=" %%D in (
        '"cmd /v:on /c echo(^!line^!|findstr http://"'
      ) do (
        if "!!" equ "" endlocal
        echo %%B: %%D
      )
    )
  )
) >c:\temp\javaurls.txt
exit /b
于 2012-12-18T17:31:34.503 回答