0
嗯..我需要的實際上只是讀取明文文件的第n行並保存在變量中以便在批處理中進一步處理。所以我一直在搜索相當長的時間,並找到了很多解決方案(全部在for循環中)。還有很多這裏堆棧溢出,但很好,沒有爲我工作。在文本文件中讀取第n行並在MS批處理中處理
這裏是我嘗試了
for /f "skip=%toskip%" %%G IN (passwd.txt) DO if not defined line set "line=%%G"
所以在這裏我的項目細節的一種方式的示例。
內容:pwcracker.bat(在下文示出)
要求:7za.exe,passwd.txt(每行1個可能的密碼數據庫)
pwcracker.bat:
@echo on
for /f %%i in ("passwd.txt") do set size=%%~zi
if %size% leq 0 (
echo Please create a dictionary of passwords first [File not found: passwd.txt]!>result.txt
exit 1
)
@Overwrite result.txt if it exists
echo [RESULT]>result.txt
@Try to delete the log if it exists
IF EXIST logging.txt del /F logging.txt
@REM If the file wasn't deleted for some reason, stop and error
IF EXIST logging.txt (
echo The log file must be removed!>>result.txt
exit 1
)
@Ask user for the file to unzip
set /p filename=Enter 7z filename [name.7z]:
@Check amount of PWs to try within the dictionary
cls
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" passwd.txt | find /C ":""
@Set the amount to try
for /f %%a in ('!cmd!') do set tries=%%a
@####################################
@Begin the for loop to try all PWs until unzipped or all PWs are tried
FOR /L %%X IN (1,1,%tries%) DO (
@Set PW to try
@CODE INPUT TO READ AND STORE PW in local variable %passwd%
@try to unzip using the given password and log the output
7za e %filename% -o%CD%\unzipped -p%passwd%>>logging.txt
@check the size of the log file
for /f %%i in ("logging.txt") do set size=%%~zi
@see whether it was succesful and log the tried password in the resuts
findstr /m "Error" logging.txt
if %errorlevel%==1 (
echo It didn't work with PW: %passwd%>>result.txt
@Try to delete the log if it exists
IF EXIST logging.txt del /F logging.txt
@REM If the file wasn't deleted for some reason, stop and error
IF EXIST logging.txt (
echo The log file couldn't be removed!>>result.txt
exit 1
)
@end of error-check clause
)
else (
if %size% leq 0 (
echo Something went wrong, please check manually>result.txt
echo Tried PW : %passwd% >>result.txt
exit 1
)
@end of prior else block
)
else (
echo Unzipped succesfully with PW: %passwd%>result.txt
exit 1
)
@end of for loop (1,1,tries)
)
這個批處理文件基本上只是「破解」我的aes加密的7zip文件,因爲我錯誤輸入了密碼,不知道它是什麼。是的,像7zcracker這樣的工具不工作,並最終陳述「密碼爲1」,但這個「工具」可以看到在解壓縮過程中是否有「錯誤」(因爲只有數據被加密,而不是名稱,7z文件可以「解壓」,但內容的大小爲0 ofc)
不幸的是,這不會以某種方式工作。我由含有TESTFILE.TXT:(「
」 =換行符註釋點擊‘發送’一次擊中輸入)
'1 5'
和try.bat含有代碼和呼應成新文件tryresult.txt並沒有輸出... –
我編輯了答案,添加'usebackq'。一定要有'ECHO ON'才能看到真正發生的事情。 – lit
謝謝。使用'usebackq',它在測試批處理文件中工作得很好。猜猜這裏是最好的,而不是整天使用谷歌搜索。現在嘗試嘗試200k以上的可能密碼大聲笑。 –