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

2016/02/24

今天有人問到如何把指令的結果同時輸出到螢幕及檔案
使用tee

date | tee -a today

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 ' ' 這樣就可以把空格全部壓縮成一個

2016/02/17

debian安裝後若不使用nfs
可以把二個service 關了

systemctl disable nfs-common
systemctl disable rpcbind
今天在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了

無言

2016/02/16

最近把server慢慢升到centos 7
一些轉換用到的東西記一下

原本使用ftp server 來傳資料 改用ssh
lftp sftp://user:password@host  -e "put local-file.name; bye"

裝好log server後使用 nc來進行測試
echo ‘<14>sourcehost message text’ | nc -v -u -w 0 server_ip 514

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就好了

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


2015/12/14

最近因為要SDN的POC
廠商要求測試的主机要有二張網卡
一張要開啟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

今天user要從gmali經由pop3收gmail的時候一直出現認証錯誤的問題
找了一些資料才知道有二個地方要設定

在被收信的帳戶中設定

第一是在帳戶的安全性中要把
[允許安全性較低的應用程式] 設定打開



再來到下方的網址把 unlockcaptcha 關閉

https://accounts.google.com/DisplayUnlockCaptcha


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 資料

2015/12/02

安裝ubuntu時第一個建立的user一定會有sudo的權限
那如何把第二個user也加入sudo的權限呢
網路上有很多方法
但都很麻煩
最簡單的方式就是

sudo usermod -G sudo newuser

一行指令解決

2015/11/19

今天有個需求
要知道目前所有使用的 poe switch 的型號
找了一下cacti好像沒辦法直接看到資料
database裡好像也沒有一個table有放
看來只好自己撈了

先把ip取出來

select hostname from host;

整理後存成 switch
再寫個shell

#!/bin/bash
for i in `cat switch`
do
echo $i
snmpwalk -v 2c -c public $i iso.3.6.1.2.1.1.1.0
done

完成

2015/11/02

今天碰到一個需求就是要把ftp mount成一個目錄來用

sudo apt-get install curlftpfs

sudo curlftpfs ftp-user:ftp-pass@my-ftp-location.local /mnt/my_ftp/
-o allow_other
How to resize the Root volume on LVM

http://ubuntuforums.org/showthread.php?t=1537569

2015/10/29

最近發生几次電子看板影片播不出來的問題
找了一下
有人說在firefox把硬体加速關掉可以解決
下次再碰到再來改看看

https://support.mozilla.org/zh-TW/questions/1044374

2015/10/26

brocade switch 本來就有loop-detection的机制 不管指令有沒有下
但實務上有時有作用有時沒作用

後來廠商說使用另一個指令

stp-bpdu-guard

之前試在第二層的switch封包會過不了
可是今天工程師來試又是ok的
找個時間來把指令下到fws上面去好了
免得只要有人接loop
switch cpu就 100%
如何把linux p2v
做法也不困難

如下

dd if=/dev/sda of=/path/bck.raw

開一個kvm
把hd指到bck.raw

2015/10/21

今天在思考一個問題
要不要把google的ip全部設成白名單
但首先要取得google的全部ip
指令如下

nslookup -q=TXT _netblocks.google.com 8.8.8.8

目前得到的資料如下

nslookup -q=TXT _netblocks.google.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
_netblocks.google.com text = "v=spf1 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:207.126.144.0/20 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"

http://itindex.net/detail/50310-google-ip-%E6%96%B9%E6%B3%95

2015/10/20

最近因為要升級switch
所以有使用tftp的需求
想找看看能不能用 python 一行指令解決
找到如下的解決方案

https://code.google.com/p/tftpgui/

解壓後跟要使用的文件放在同一個目錄
執行
sudo python tftpgui.py --nogui
即可
相當方便