上週認証設備掛點
除了認証失效外
因為流量的計算也在該台上 所以quota的限制也就失效了
本來想直接撈LP的netflow資料來算
但因為會包含內部對內部的流量 所以會造成問題
因此打算用對外port mirror的資料轉成netflow來使用
fprobe
把port mirror的資料轉成netflow格式再吐出來
flow-tools
收集netflow並格式化成所需的資料
在ubuntu上直接apt-get install就好了
centos沒辦法直接yum
相關指令如下
/usr/sbin/fprobe -ieth1 -fip localhost:555
/usr/bin/flow-capture -V 5 -z 6 -n 572 -e 5000 -N -1 -w /tmp/flow 0/0/555
計算流量排名指令如下
取出超過10G下載或上傳量的ip
flow-cat /tmp/flow/`date +'%Y-%m-%d'`/ft*|flow-report -v TYPE=ip-destination-address|grep "192.168.\|10.10."|sort -rnk3 |awk '$3 > 5000000000 {print $1}'|grep -v -f /root/netflow_white_list > /tmp/netflow_quota_download
flow-cat /tmp/flow/`date +'%Y-%m-%d'`/ft*|flow-report -v TYPE=ip-source-address|grep "192.168.\|10.10."|sort -rnk3 |awk '$3 > 5000000000 {print $1}'|grep -v -f /root/netflow_white_list > /tmp/netflow_quota_upload
https://jal.tw/doku.php?id=netflow:fprobe
2016/03/29
2016/03/22
為了預先解決centos 5到明天支援到期的問題
今天來把原先提供下載服務的机器升成centos 7
比較難處理的是原本提供kms認証的部分
几個跟原centos 5不同的地方記錄一下
原本apache用來ldap認証的模組換成 mod_ldap
寫法也有一些改變 範例如下 (novell 適用)
<Directory /var/www/html/test>
AuthName ldap
AuthType Basic
AuthBasicProvider ldap
AuthLDAPURL ldap://test.com.tw:389/o=users?cn?sub?(objectClass=*)
AuthLDAPBindDN "cn=user01, ou=user, ou=people, o=users"
AuthLDAPBindPassword password
Require valid-user
</Directory>
ip forword的寫法也改了
在/etc/sysctl.conf 加上
net.ipv4.ip_forward = 1
重新載入
sysctl -p /etc/sysctl.conf
http://my.oschina.net/fsxchen/blog/134601
http://superuser.com/questions/803741/how-to-enable-ip-masquerading-forwarding-on-centos-7
今天來把原先提供下載服務的机器升成centos 7
比較難處理的是原本提供kms認証的部分
几個跟原centos 5不同的地方記錄一下
原本apache用來ldap認証的模組換成 mod_ldap
寫法也有一些改變 範例如下 (novell 適用)
<Directory /var/www/html/test>
AuthName ldap
AuthType Basic
AuthBasicProvider ldap
AuthLDAPURL ldap://test.com.tw:389/o=users?cn?sub?(objectClass=*)
AuthLDAPBindDN "cn=user01, ou=user, ou=people, o=users"
AuthLDAPBindPassword password
Require valid-user
</Directory>
ip forword的寫法也改了
在/etc/sysctl.conf 加上
net.ipv4.ip_forward = 1
重新載入
sysctl -p /etc/sysctl.conf
因為需要使用apche這個身分下iptables的指令
所以要編輯 /etc/sudoers
Defaults requiretty 改為 Defaults:apache !requiretty apache不需要tty
再加上
User_Alias APACHE = apache
Cmnd_Alias FIREWALL = /sbin/iptables
APACHE ALL = (ALL) NOPASSWD: FIREWALL
原來的firewalld要停掉 改用iptables
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
http://my.oschina.net/fsxchen/blog/134601
http://superuser.com/questions/803741/how-to-enable-ip-masquerading-forwarding-on-centos-7
2016/03/05
最近把從mysql撈資料的程式用python改寫 之前是用php
改完後發生的第一個問題就是中文全變成了???
192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking ????????????(1368>????:700) to Deny this IP cannot access network
原因是從mysql撈出來時中文就亂了 所以不管之後怎麼轉碼 都沒有用了
所以必須在撈時就要指定編碼 加上下方紅色字部分
db = MySQLdb.connect(host="localhost", user="abc", passwd="pwd", db="test", charset='utf8')
但加完後網頁反而出不來了
再查了一下資料 說是要再指定sys的編碼 於是程式內必需再加入以下三行
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
加完後之後的結果變成
192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking �訫�銝餅�����賊�蝬脰楝�輻�(1368>�𣂼��賊�:700) to Deny this IP cannot access network
看來中文有出來了 接下來是顯示的問題了 因為這個os比較久了 所以apache預設的編碼是設為big5 如果要去改會影響到其他東東 所以只能在程式加上指定編碼來處理了 比較新版本os的apache應該都預設為utf8了 應該不會碰到這個問題
print '<html>'
print '<head>'
print '<meta charset="UTF-8">'
print '</head>'
print '<body>'
print '</body>'
print '</html>'
改完後發生的第一個問題就是中文全變成了???
192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking ????????????(1368>????:700) to Deny this IP cannot access network
原因是從mysql撈出來時中文就亂了 所以不管之後怎麼轉碼 都沒有用了
所以必須在撈時就要指定編碼 加上下方紅色字部分
db = MySQLdb.connect(host="localhost", user="abc", passwd="pwd", db="test", charset='utf8')
但加完後網頁反而出不來了
再查了一下資料 說是要再指定sys的編碼 於是程式內必需再加入以下三行
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
加完後之後的結果變成
192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking �訫�銝餅�����賊�蝬脰楝�輻�(1368>�𣂼��賊�:700) to Deny this IP cannot access network
看來中文有出來了 接下來是顯示的問題了 因為這個os比較久了 所以apache預設的編碼是設為big5 如果要去改會影響到其他東東 所以只能在程式加上指定編碼來處理了 比較新版本os的apache應該都預設為utf8了 應該不會碰到這個問題
print '<html>'
print '<head>'
print '<meta charset="UTF-8">'
print '</head>'
print '<body>'
print '</body>'
print '</html>'
網頁正常 搞定
192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking 違反主機連線數量網路政策(1368>限制數量:700) to Deny this IP cannot access network
完整程式碼如下
#!/usr/bin/python
# -*- coding: utf-8 -*-
print "Content-type: text/html"
print
# 引入 MySQL 模組
import MySQLdb
#引入 sys 並指定sys為utf-8編碼
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# 連接 MySQL
db = MySQLdb.connect(host="localhost", user="abc", passwd="pwd", db="test", charset='utf8')
cursor = db.cursor()
# 執行 SQL
cursor.execute("select ip from table;")
result = cursor.fetchall()
# 輸出結果
a=0
for record in result:
if (a%2)==1:
print "<FONT COLOR=FF0000>"
else:
print "<FONT COLOR=000000>"
print record[0]
print "<br>"
print "<br>"
a=a+1
db.close()
最近在ubuntu 32 位元 開啟chrome時都會出現不在支援此版本的作業系統
表示以後不再支援32位元的版本了
今天要update時出現
W: 無法取得 http://dl.google.com/linux/chrome/deb/dists/stable/Release,在 Release 檔案找不到要有的「main/binary-i386/Packages」項目 (sources.list 項目有問題或檔案格式不對)
可是連64位元的os都出現 XD
要修正一下 source list
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
表示以後不再支援32位元的版本了
今天要update時出現
W: 無法取得 http://dl.google.com/linux/chrome/deb/dists/stable/Release,在 Release 檔案找不到要有的「main/binary-i386/Packages」項目 (sources.list 項目有問題或檔案格式不對)
可是連64位元的os都出現 XD
要修正一下 source list
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
2016/03/04
2016/02/29
關於如何在網頁上執行python目前找到二個方法
一個是在apache中載入module
有二個module可以用
http://modpython.org/
https://code.google.com/archive/p/modwsgi/
根據一般的說法是wsgi的效能會比modpython好二倍以上
使用方式是在apache啟動時載入模組
另一個方式是採用cgi
直接把寫好的python放在 /var/www/cgi-bin/下
在程式碼的最前面加上
print "Content-type: text/html"
print
這樣就能直接用了
bash perl 也是相同的方法
目前先採用cgi的方式
http://blog.xuite.net/autosun/study/42871538-%5BUbuntu%5D+%E5%AE%89%E8%A3%9D+Apache2+%2B+Python+%2B+MySQL
一個是在apache中載入module
有二個module可以用
http://modpython.org/
https://code.google.com/archive/p/modwsgi/
根據一般的說法是wsgi的效能會比modpython好二倍以上
使用方式是在apache啟動時載入模組
另一個方式是採用cgi
直接把寫好的python放在 /var/www/cgi-bin/下
在程式碼的最前面加上
print "Content-type: text/html"
這樣就能直接用了
bash perl 也是相同的方法
目前先採用cgi的方式
http://blog.xuite.net/autosun/study/42871538-%5BUbuntu%5D+%E5%AE%89%E8%A3%9D+Apache2+%2B+Python+%2B+MySQL
2016/02/24
2016/02/20
昨天發現有几台brocade的fan壞了
本來在crontab是有寫檢查fail及error的script
但因為brocade 在log上會一直出現fan
因為會一直變換轉速
所以之前拿掉了 因為量太大
這次再加回去
grep Fan|grep fail
但要撈log時 使用cut時發現一個問題
當每個月的10號之前
會有二個空格
Apr 9 19:37:20 192.168.204.251 System: Fan 1 (from left when facing right side), failed
Apr和9間就有二個空格
如此便會影使用cut取值的正確
為了要解決這個問題
使用一次 tr 就好了
tr -s ' ' 這樣就可以把空格全部壓縮成一個
本來在crontab是有寫檢查fail及error的script
但因為brocade 在log上會一直出現fan
因為會一直變換轉速
所以之前拿掉了 因為量太大
這次再加回去
grep Fan|grep fail
但要撈log時 使用cut時發現一個問題
當每個月的10號之前
會有二個空格
Apr 9 19:37:20 192.168.204.251 System: Fan 1 (from left when facing right side), failed
Apr和9間就有二個空格
如此便會影使用cut取值的正確
為了要解決這個問題
使用一次 tr 就好了
tr -s ' ' 這樣就可以把空格全部壓縮成一個
2016/02/17
今天在config centos 7的vsftpd
主要几個地方
不允許anonymous
anonymous_enable=NO
限制user只能在自己的home目錄
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
在 /etc/vsftpd 產生一個 chroot_list 檔案
touch chroot_list
改完後 systemctl restart vsftpd
但要登入時發生
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
找了半天資料 罵聲一片
最後才找到新版要再多加一行
allow_writeable_chroot=YES
加完重啟就ok了
無言
主要几個地方
不允許anonymous
anonymous_enable=NO
限制user只能在自己的home目錄
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
在 /etc/vsftpd 產生一個 chroot_list 檔案
touch chroot_list
改完後 systemctl restart vsftpd
但要登入時發生
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
找了半天資料 罵聲一片
最後才找到新版要再多加一行
allow_writeable_chroot=YES
加完重啟就ok了
無言
2016/02/16
2016/02/15
今天本來是要升級OCS
但升到2.2後畫面竟然只有几個數字
而且升級的過程一直不順
想說重裝好了
因為原來是裝在centos 5上
而centos 5 的EOL是2017年3 月
所以試看看裝在centos 7 會不會比較沒問題
查了一下
現在在centos 7 上裝很簡單了
稍微記錄一下
最小安裝後改一下hosts.allow hosts.deny 及selinux
關掉filewalld
systemctl stop firewalld
systemctl disable firewalld
再裝一下net-tools及 epel-release
epel-release是用來加入額外repo
安裝mariadb
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
修改mariadb的root密碼及一些安全設定
mysql_secure_installation
再來安裝ocs
yum install -y ocsinventory-server ocsinventory-reports
因為加入了epel-release 所以系統會把所有相依性的套件一次裝好
啟動httpd服務
systemctl start httpd
sytemctl enable httpd
接下來就可以進入web介面 依畫面指示進行接下來的安裝動作了
http://ocs-server-ip/ocsreports/
預設登入帳號密碼是 admin/admin 記得要改
修改server ip 使用文字化圖形介面指令
nmtui
目前的版本是2.1.2
再等一陣子看看 應該會直接升到 2.2 到時直接使用yum update就好了
但升到2.2後畫面竟然只有几個數字
而且升級的過程一直不順
想說重裝好了
因為原來是裝在centos 5上
而centos 5 的EOL是2017年3 月
所以試看看裝在centos 7 會不會比較沒問題
查了一下
現在在centos 7 上裝很簡單了
稍微記錄一下
最小安裝後改一下hosts.allow hosts.deny 及selinux
關掉filewalld
systemctl stop firewalld
systemctl disable firewalld
再裝一下net-tools及 epel-release
epel-release是用來加入額外repo
安裝mariadb
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
修改mariadb的root密碼及一些安全設定
mysql_secure_installation
再來安裝ocs
yum install -y ocsinventory-server ocsinventory-reports
因為加入了epel-release 所以系統會把所有相依性的套件一次裝好
啟動httpd服務
systemctl start httpd
sytemctl enable httpd
接下來就可以進入web介面 依畫面指示進行接下來的安裝動作了
http://ocs-server-ip/ocsreports/
預設登入帳號密碼是 admin/admin 記得要改
修改server ip 使用文字化圖形介面指令
nmtui
目前的版本是2.1.2
再等一陣子看看 應該會直接升到 2.2 到時直接使用yum update就好了
2016/01/11
昨天看到這個工具還不錯 fastnetmon
https://github.com/pavel-odintsov/fastnetmon
可以使用netflow sflow port mirror的資料來計算pps mbps 及flow數
當到達指定的上限時
可以發出告警或執行特定動作
安裝很簡單
裝好centos 7後
wget https://raw.githubusercontent.com/pavel-odintsov/fastnetmon/master/src/fastnetmon_install.pl -Ofastnetmon_install.pl
perl fastnetmon_install.pl
會自動把需要的套件補齊
裝好後依需求修改 /etc/fastnetmon.conf
另外在/tmp找到notify_about_attack.sh
cp到/usr/local/bin/ 一樣依需求修改內容
如果使用port mirror 要把網卡的 promisc打開
寫入 /etc/rc.local
/usr/sbin/ifconfig eth1 promisc
再來設定開机執行 fastnetmon
systemctl enable fastnetmon
以下的程式可以觀看即時的狀況
/opt/fastnetmon/fastnetmon_client
https://github.com/pavel-odintsov/fastnetmon
可以使用netflow sflow port mirror的資料來計算pps mbps 及flow數
當到達指定的上限時
可以發出告警或執行特定動作
安裝很簡單
裝好centos 7後
wget https://raw.githubusercontent.com/pavel-odintsov/fastnetmon/master/src/fastnetmon_install.pl -Ofastnetmon_install.pl
perl fastnetmon_install.pl
會自動把需要的套件補齊
裝好後依需求修改 /etc/fastnetmon.conf
另外在/tmp找到notify_about_attack.sh
cp到/usr/local/bin/ 一樣依需求修改內容
如果使用port mirror 要把網卡的 promisc打開
寫入 /etc/rc.local
/usr/sbin/ifconfig eth1 promisc
再來設定開机執行 fastnetmon
systemctl enable fastnetmon
以下的程式可以觀看即時的狀況
/opt/fastnetmon/fastnetmon_client
標籤:
centos 7,
fastnetmon,
netflow,
port mirror,
promiscuous,
sflow,
systemctl
2015/12/14
最近因為要SDN的POC
廠商要求測試的主机要有二張網卡
一張要開啟promiscuous mode 用來聽所有對外的封包
本來是想放在vm上
但之前要把snort及其他網管軟体移進vm時也一直在找相關的資料
那時就沒找到要如何解決
因為在guest裡就是看不到所有的封包
上週也到proxmox的官方forum上去問
過了好几天也沒人回文
昨天終於找到解決方法了
原來這麼解單
把網卡的bridge設為HUB mode就好了
指令如下
brctl setageing vmbr1 0
順便來去官網自我回文
廠商要求測試的主机要有二張網卡
一張要開啟promiscuous mode 用來聽所有對外的封包
本來是想放在vm上
但之前要把snort及其他網管軟体移進vm時也一直在找相關的資料
那時就沒找到要如何解決
因為在guest裡就是看不到所有的封包
上週也到proxmox的官方forum上去問
過了好几天也沒人回文
昨天終於找到解決方法了
原來這麼解單
把網卡的bridge設為HUB mode就好了
指令如下
brctl setageing vmbr1 0
順便來去官網自我回文
20240301 修正
以上所述下指令的方式在proxmox 8版沒作用了
要修改以下檔案
重開才能生效
/etc/network/interfaces
把listen的介面加上
bridge_ageing 0
範例如下
auto vmbr1
iface vmbr1 inet manual
bridge-ports ens1f1
bridge-stp off
bridge-fd 0
bridge_ageing 0
重開才能生效
2015/12/10
2015/12/04
最近開始直接向各國回報攻擊我們的ip
今天終於有一個國家回信 是日本
好感動
請我再提供log的時區及純文字檔
snort base 無法直接匯出
記錄一下sql語法
select event.cid,signature,sig_name,inet_ntoa(iphdr.ip_src),tcphdr.tcp_sport,inet_ntoa(iphdr.ip_dst),tcphdr.tcp_dport,timestamp from iphdr,event,signature,tcphdr where event.signature=signature.sig_id and event.cid=iphdr.cid and event.cid=tcphdr.cid and event.timestamp like '2015-12-04%' and inet_ntoa(iphdr.ip_src)="133.208.26.134" into outfile '/tmp/133.208.26.134.log';
事件的唯一值是 event裡的cid 其他table都要參考這個值
iphdr 放的是ip資料
tcphdr 放的是tcp的相關port 資料
udphdr 放的是udp的相關port 資料
今天終於有一個國家回信 是日本
好感動
請我再提供log的時區及純文字檔
snort base 無法直接匯出
記錄一下sql語法
select event.cid,signature,sig_name,inet_ntoa(iphdr.ip_src),tcphdr.tcp_sport,inet_ntoa(iphdr.ip_dst),tcphdr.tcp_dport,timestamp from iphdr,event,signature,tcphdr where event.signature=signature.sig_id and event.cid=iphdr.cid and event.cid=tcphdr.cid and event.timestamp like '2015-12-04%' and inet_ntoa(iphdr.ip_src)="133.208.26.134" into outfile '/tmp/133.208.26.134.log';
事件的唯一值是 event裡的cid 其他table都要參考這個值
iphdr 放的是ip資料
tcphdr 放的是tcp的相關port 資料
udphdr 放的是udp的相關port 資料
2015/12/02
2015/11/19
訂閱:
文章 (Atom)
