php 檢測圖片木馬(多進位編程)的代碼

來源:互聯網
上載者:User
本文分享下,php實現的檢測圖片木馬的一段代碼,可用於檢測十六制編碼的木馬程式,有需要的朋友參考下吧。

本php檢測圖片木馬的程式,從製作原理來分析木馬程式。有些木馬程式是十六進位編碼寫的,因此需要花些心思做檢測,於是實現了這個php木馬檢測類。

代碼:

 '沒有錯誤發生,檔案上傳成功。', '1' => '上傳的檔案超過了 php.ini 中 upload_max_filesize 選項限制的值。', '2' => '上傳檔案的大小超過了 HTML 表單中 MAX_FILE_SIZE 選項指定的值。', '3' => '檔案只有部分被上傳。', '4' => '沒有檔案上傳。', '5' => '未能通過安全檢查的檔案。', '6' => '找不到臨時檔案夾。', '7' => '檔案寫入失敗。', '8' => '檔案類型不支援', '9' => '上傳的臨時檔案丟失。', ); //@ 開始執行檔案上傳 public static function start($feild = 'file') { if (!empty($_FILES)) { self::$status = $_FILES[$feild]['error']; if (self::$status > 0) return array('status' => self::$status, 'msg' => self::$message[self::$status]); self::$image = $_FILES[$feild]['tmp_name']; self::$suffix = strtolower(strrchr($_FILES[$feild]['name'], '.')); return array('status' => self::_upload(), 'path' => self::$image, 'msg' => self::$message[self::$status]); } else { return array('status' => self::$status, 'msg' => self::$message[self::$status]); } } //@ 私人 上傳開始 private static function _upload($path = './upload/') { date_default_timezone_set('PRC'); $newFile = $path . date('Y/m/d/His') . rand(100, 999) . self::$suffix; self::umkdir(dirname($newFile)); if (is_uploaded_file(self::$image) && move_uploaded_file(self::$image, $newFile)) { self::$image = $newFile; if (in_array(self::$suffix, self::$imageType)) return self::checkHex(); else return self::$status = 0; } else { return self::$status = 9; } } //@ 私人 16進位檢測 private static function checkHex() { if (file_exists(self::$image)) { $resource = fopen(self::$image, 'rb'); $fileSize = filesize(self::$image); fseek($resource, 0); if ($fileSize > 512) { // 取頭和尾 $hexCode = bin2hex(fread($resource, 512)); fseek($resource, $fileSize - 512); $hexCode .= bin2hex(fread($resource, 512)); } else { // 取全部 $hexCode = bin2hex(fread($resource, $fileSize)); } fclose($resource); /* 匹配16進位中的 <% ( ) %> */ /* 匹配16進位中的  */ /* 匹配16進位中的 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.