2017-04-02 22 views
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) 
    ) 

このバッチファイルは、私がパスワードを間違って入力して、それがどういうものなのか分からないので、基本的に私のエースで暗号化された7zipファイルを "クラック"します。そして、ええ、7zcrackerのようなツールはうまく動作せず、 "passwodは1" btwでしたが、この「ツール」は解凍中に「エラー」があったかどうかを確認できます(データのみが暗号化されているため名前は、7zファイルは "解凍"できますが、コンテンツのサイズは0cです)

答えて

0

triesの番号を取得する必要はありません。パスワードファイルの各行を読むだけです。

FOR /F "usebackq tokens=*" %%p IN (`TYPE passwd.txt`) DO (
    ECHO Trying password %%p 
    REM try the password 
) 
+0

残念ながら、これは何とか動作しません。私は含んでTESTFILE.TXTを作った:
'1 5'(「
」=改行コメントは一度入るヒット『送信』を押します。)
とtry.batあなたのコードを含むとにエコー新しいファイルtryresult.txtと出力がありませんでした... –

+0

私は 'usebackq'を追加する答えを編集しました。実際に何が起こっているかを見るためには、 'ECHO ON'を必ず付けてください。 – lit

+0

ありがとうございます。 'usebackq'を実行すると、テストバッチファイル内ですべて正常に機能しました。ここで尋ねると、一日中グーグルグーグルではなく最高だったと思う。 200kと可能なパスワードを試してみましょう。 –

関連する問題