2013-07-23 54 views
0

第一次在這裏,我有一個問題,如果你能解決我我會非常感謝你們所有人。 我正在做一個HIDS項目,當我在linux上運行我的代碼時(CENTOS 6.3)效果很好,但是當我嘗試在網頁腳本上運行它時apache只是不起作用很好。我的代碼上Python的Apache不運行我的Python代碼

def sniffcometome(userbd,passbd): 
    db= mysql.connect("localhost",userbd,passbd,"HIDS") 
    cursor = db.cursor() 
    proc = subprocess.Popen("ps -eo user | grep -v root | grep -v apache",shell=True,executable='/bin/bash',stdout=subprocess.PIPE,stderr=subprocess.PIPE) 
    (out,err) = proc.communicate() 
    out = out.split() 
    n = len(out) 
    print "Content-Type: text/html\r\n\r\n" 
    for i in range (n): 
      sql = "select program from SNIFFER where program = '%s'"%(out[i]) 
      #print out[i] 
      cursor.execute(sql) 
      result = cursor.fetchone() 
      if result != None: 
        SendMail('ALERT: Sniffer detected!') 
        print "Content-type: text/html\r\n\r\n" 
        print "Success" 
    cursor.close() 
    db.close() 

    print "Content-type: text/html\n\n" 
    print "Success" 

當我在CentOS運行此輸出

['USER', 'rpc', 'dbus', 'avahi', 'avahi', 'rpcuser', 'haldaemon', 'haldaemon', 'mysql', 'postfix', 'postfix', 'tcpdump'] 

當我上運行Apache僅此輸出

['USER'] 

謝謝你們!祝你有愉快的一天!

+0

您確定您是以完全相同的方式手動運行腳本嗎?例如:什麼用戶運行Apache?你可以檢查'我是誰'。也許這個用戶不能看到所有的進程? – Jensd

+0

我在root和其他用戶中以這種方式運行此命令「python hids_verif.py」,並且我得到正在運行的proccesses列表。我檢查我的腳本中的「whoami」,並說「apache」。 – luifer99

回答

0

出於安全原因,您不是Apache服務器在監獄環境中運行嗎?你確定ps能看到這個環境的全部內容嗎?

+0

我不知道如何看到,對不起,我有點新與Linux和Apache。你能告訴我,我怎麼能看到?謝謝! – luifer99