0

そこで私は、コンピューター上で実行され、私たちを悩ませてきたファイルの特定の側面を探し、フラグが渡された場合にファイルを削除するプログラムを設計しました。残念ながら、プログラムはほぼランダムにシャットダウン/クラッシュしているようです。ファイルを削除すると、プログラムは常に終了しますが、通常は成功した後もそのままになります。

同じ間隔で上向きにカウントする並列 Python プログラムを実行しましたが、他には何もしません。このプログラムはクラッシュ/終了せず、開いたままになります。

おそらく R/W アクセスの問題がありますか? 私は管理者としてプログラムを実行しているので、なぜそうなるのかわかりません。

コードは次のとおりです。

import glob
import os
import time
import stat

#logging
import logging
logging.basicConfig(filename='disabledBots.log')
import datetime


runTimes = 0
currentPhp = 0
output = 0
output2 = 0
while runTimes >= 0:
    #Cycles through .php files
    openedProg = glob.glob('*.php')
    openedProg = openedProg[currentPhp:currentPhp+1]
    progInput = ''.join(openedProg)
    if progInput != '':
        theBot = open(progInput,'r')

        #Singles out "$output" on this particular line and closes the process
        readLines = theBot.readlines()
        wholeLine = (readLines[-4])
        output = wholeLine[4:11]

        #Singles out "set_time_limit(0)"
        wholeLine2 = (readLines[0])
        output2 = wholeLine2[6:23]

        theBot.close()
    if progInput == '':
        currentPhp = -1

    #Kills the program if it matches the code
    currentTime = datetime.datetime.now()
    if output == '$output':
        os.chmod(progInput, stat.S_IWRITE)
        os.remove(progInput)
        logging.warning(str(currentTime) +' ' + progInput + ' has been deleted. Please search for a faux httpd.exe process and kill it.')
        currentPhp = 0

    if output2 == 'set_time_limit(0)':
        os.chmod(progInput, stat.S_IWRITE)
        os.remove(progInput)
        logging.warning(str(currentTime) +' ' + progInput + ' has been deleted. Please search for a faux httpd.exe process and kill it.')
        currentPhp = 0
    else:
        currentPhp = currentPhp + 1
        time.sleep(30)

    #Prints the number of cycles    
    runTimes = runTimes + 1
    logging.warning((str(currentTime) + ' botKiller2.0 has scanned '+ str(runTimes) + ' times.'))
    print('botKiller3.0 has scanned ' + str(runTimes) + ' times.')
4

2 に答える 2

1

まず、このようなものに基づいてコードを作成すると、何が起こっているのかを理解するのが非常に簡単になります...

for fname in glob.glob('*.php'):
    with open(fname) as fin:
        lines = fin.readlines()
    if '$output' in lines[-4] or 'set_time_limit(0)' in lines[0]:
        try:
            os.remove(fname)
        except IOError as e:
            print "Couldn't remove:", fname

そして、それは現時点では実際には 2 番目ではありません。既存のコードは、私たちがまだ知らない奇妙なエラーを引き起こす可能性のあるすべてのビットは言うまでもなく、フルストップに従うにはトリッキーすぎます!

于 2012-12-14T21:32:20.200 に答える
0
if os.path.exists(progInput): 
    os.chmod(progInput, stat.S_IWRITE)
    os.remove(progInput)

また:

ループ内のoutput変数またはoutput2変数をリセットしたことはありませんか?

これはわざとですか?

于 2012-12-14T21:26:32.933 に答える