Windows 2008 サーバーのイベント ログから特定のイベントで ips を禁止する python(3.2) スクリプトを作成し、SQL ブルート フォーシング試行から ips を適切に禁止するかどうかをテストしようとしていました。残念ながら、探しているイベント ID が表示されないため (ログ ファイルには表示されるはずですが)、コードのその部分に到達していません。
def run_script_application_log():
eventIds = [18456] #look for these events to process for possible ip bans 18456 = failed login
server = 'localhost' # name of the target computer to get event logs from
logtype = 'Application' # 'Application' or 'Security' etc...
hand = win32evtlog.OpenEventLog(server,logtype)
ipsToBan = look_for_ips_to_ban(hand,flags,eventIds)
def look_for_ips_to_ban(hand, flag, eventIds):
...some code....
events=1
while events:
events=win32evtlog.ReadEventLog(hand,flag,0)
for event in events:
the_time=event.TimeGenerated.Format()
seconds=date2sec(the_time)
#if seconds < begin_sec - time_in_seconds: break
if event.EventID in eventIds:
event.EventID で何が起こっているかを確認するために簡単な print ステートメントを挿入しましたが、得られた数値は控えめに言っても奇妙でした。イベント ログは 33090 まで上がりますが、返される ID の大部分は次のようなものです: 1073750020 1073754112 -1073741823 -2147481364
何が起こっているのかわかりません。セキュリティログでは問題なく動作しますが、アプリケーションログはうまくいかないようです.
いくつかのデータを調べたところ、eventID を除いてすべて正しく報告されているようです。
たとえば、ログのこのレコードは、イベント ID が 18456 ではなく 1073742726 であることを除いて、すべて正しいです。
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="MSSQLSERVER" />
<EventID Qualifiers="49152">18456</EventID>
<Level>0</Level>
<Task>4</Task>
<Keywords>0x90000000000000</Keywords>
<TimeCreated SystemTime="2012-12-08T18:01:32.000000000Z" />
<EventRecordID>4532</EventRecordID>
<Channel>Application</Channel>
<Computer>windowsmachine</Computer>
<Security />
</System>
<EventData>
<Data>username</Data>
<Data>Reason: Password did not match that for the login provided.</Data>
<Data>[CLIENT: <local machine>]</Data
<Binary>184800000E0000000A000000570049004E004D00430041005000460058000000070000006D00610073007400650072000000</Binary>
</EventData>
</Event>