顯示具有 freebsd 標籤的文章。 顯示所有文章
顯示具有 freebsd 標籤的文章。 顯示所有文章

2020年8月24日 星期一

FreeBSD apache24 with letsencrypt

安裝

pkg install py37-certbot


----------

先測試是否可正常下載憑證

certbot certonly --standalone -d example.tw --dry-run

成功的話再下

certbot certonly --standalone -d example.tw

檔案會放在

/usr/local/etc/letsencrypt/live/example.tw/


----------

編輯httpd.conf

Listen 443

LoadModule ssl_module libexec/apache24/mod_ssl.so

<VirtualHost *:443>

    ServerName example.tw

    DocumentRoot /home/example/www

    SSLEngine on

    SSLCertificateFile "/usr/local/etc/letsencrypt/live/example.tw/cert.pem"

    SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/example.tw/privkey.pem"

    SSLCertificateChainFile /usr/local/etc/letsencrypt/live/example.tw/chain.pem

</VirtualHost>

FreeBSD apache24 with mod_security

 安裝

pkg install ap24-mod_security


----------

apache24啟用mod_security

*把註解拿掉


ee /usr/local/etc/apache24/modules.d/280_mod_security.conf


LoadModule unique_id_module libexec/apache24/mod_unique_id.so

LoadModule security2_module libexec/apache24/mod_security2.so

Include /usr/local/etc/modsecurity/*.conf

Include /usr/local/etc/modsecurity/activated_rules/*.conf


----------

抓取core rule set檔案

fetch https://github.com/coreruleset/coreruleset/archive/v3.3.0.tar.gz


tar zxvf v3.3.0.tar.gz


cd coreruleset-3.3.0

cp crs-setup.conf.example /usr/local/etc/modsecurity/


cd rules

cp * /usr/local/etc/modsecurity/


----------

重新啟動apache

service apache24 restart


----------

測試

開啟一個不存在的網頁

http://example.com/aaaa.php

or

curl -Ik https://example.tw/?abc=../../

可以在/var/log/modsec_audit.log看到紀錄

2020年8月13日 星期四

2019年5月24日 星期五

nikto 安裝及使用

#安裝
>pkg install perl5
>pkg install git
>git clone https://github.com/sullo/nikto.git Nikto2

#更新
>cd Nikto2
>git pull

#使用
>cd Nikto2/program

##掃描https
>perl nikto.pl -h https://123.edu.tw/ -ssl
##掃描http
>perl nikto.pl -h http://123.edu.tw/
##掃描特定資料夾
>perl nikto.pl -h http://123.edu.tw/billing/

2018年12月28日 星期五

freebsd 設定 NTP 自動校時

方法一
1. 編輯rc.conf
>ee /etc/rc.conf

ntpd_enable="YES"

2.編輯ntp.conf
>ee /etc/ntp.conf

server  168.95.1.1     iburst

restrict default ignore
restrict -6 default ignore

restrict 168.95.1.1

#以上為本機校時,加入下面則開放該網段可連線校時
restrict 192.168.1.0 mask 255.255.255.0 nomodify

3.啟動ntpd
>/etc/rc.d/ntpd start

==================================================

方法二
編輯 crontab
>ee /etc/crontab

#每天四點校時
0 4 * * * root /usr/sbin/ntpdate time.stdtime.gov.tw

==================================================

方法三
1.新增daily執行script
>ee /etc/periodic/daily/600.ntpdate
#!/bin/sh
echo
echo '主機校時'
/usr/sbin/ntpdate time.stdtime.gov.tw

2.更改600.ntpdate權限
>chmod +x 600.ntpdate

2018年9月7日 星期五

使用ip取得電腦名稱及mac address


nmap --script smb-os-discovery 192.168.0.1

抓以下兩個區塊的資料

MAC Address: 4C:CC:6A:77:A5:98 (Micro-star Intl)

Host script results:
| smb-os-discovery:
|   OS: Windows 7 Enterprise 7601 Service Pack 1 (Windows 7 Enterprise 6.1)
|   OS CPE: cpe:/o:microsoft:windows_7::sp1
|   Computer name: xx
|   NetBIOS computer name: xx\x00
|   Workgroup: xxgroup\x00
|_  System time: 2018-09-07T10:03:26+08:00

2018年6月25日 星期一

取得台灣IP列表

取得台灣IPv4列表
#fetch http://ftp.apnic.net/stats/apnic/delegated-apnic-latest

#netmask `cat delegated-apnic-latest | awk -F'|' '/TW\|ipv4/ {print $4":+"($5-1)}'` > tw_ip_range.txt

2018年5月30日 星期三

FreeBSD 11.1 安裝 Mellanox Connect-X2 (MNPA19-XTR) 10G 網卡

#更新 /usr/src
>svnlite checkout https://svn.freebsd.org/base/releng/11.1 /usr/src

#編譯及安裝 mlx4 模組
>cd /usr/src/sys/modules/mlx4
>make
>make install

#編譯及安裝 mlxen 模組
>cd /usr/src/sys/modules/mlxen
>make
>make install

#載入模組
>kldload mlx4
>kldload mlxen

#加入開機載入
>ee /boot/loader.conf
+ mlx4_load="YES"
+mlxen_load="YES"

#查看模組是否載入
>kldstat
 7    2 0xffffffff82628000 3123c    mlx4.ko
 8    2 0xffffffff8265a000 103e1    linuxkpi.ko
 9    1 0xffffffff8266b000 1240d    mlxen.ko

#ifconfig 可以看到 mlxen0 這張網卡
mlxen0: flags=8802 metric 0 mtu 1500
        options=ed07bb
        ether 00:02:c9:51:f9:5a
        hwaddr 00:02:c9:51:f9:5a
        nd6 options=29
        media: Ethernet autoselect
        status: no carrier




參考網站:https://frankchang.me/2017/05/02/Enable-Mellanox-Connect-X2-10G-NIC-in-FreeBSD-11/

freebsd 11.1 update /usr/src

今天在安裝光纖網卡時,遇到要重新編譯kernel,在更新/usr/src時發現跟以往不太相同,故筆記做個紀錄。


#更新/usr/src指令
>svnlite update /usr/src

#在此指令遇到錯誤訊息
'/usr/src' is not a working copy

#查了網站說明後改用以下指令,網址後面的11.1是目前系統版本,可用uname -r查看

>svnlite checkout https://svn.freebsd.org/base/releng/11.1 /usr/src

PS:
1.參考網站:https://www.freebsd.org/doc/handbook/makeworld.html#updating-src-obtaining-src
2.系統預設沒有安裝svn,我看有svnlite指令,執行後可達到相同功能

2018年4月25日 星期三

webssh2

#安裝git
>pkg install git

#安裝npm
>pkg install npm

#下載webssh2
>git clone https://github.com/billchurch/WebSSH2

>cd WebSSH2/app

#複製config.json
>cp config.json.example config.json

#安裝webssh2
>npm install --production

#啟動服務
>npm start

2018年4月18日 星期三

arping

#功能
檢查該IP是否在線上


#安裝
pkg install arping

#同網段使用
arping 10.10.1.1

#不同網段無法使用
#不同網段使用 
arping -i bridge0 10.10.2.1

#控制發送封包次數
arping -i bridge0 -c 1 10.10.2.1

2017年11月30日 星期四

安裝 owncloud 於 FreeBSD 11.1

1.安裝apache + php + mysql

>pkg install apache24
>pkg install php56
>pkg install mysql56-server
>pkg install mod_php56
>pkg install phpmyadmin

2.安裝 owncloud
>pkg install owncloud

>ee /usr/local/etc/apache24/httpd.conf

Alias /owncloud /usr/local/www/owncloud
AcceptPathInfo On

    AllowOverride All
    Require all granted



3.mysql建立owncloud使用帳號及資料庫

4.進入 http://localhost/owncloud/ 設定管理者帳號及資料庫資訊

2017年10月25日 星期三

OpenVAS 9 on FreeBSD

安裝OpenVAS9
>pkg install openvas9

>ee /etc/rc.conf

redis_enable="YES"
openvassd_enable="YES"
openvassd_flags=""
openvasmd_enable="YES"
openvasmd_flags=""
gsad_enable="YES"
gsad_flags="--listen=0.0.0.0 --port=9392 --http-only"


>cp /usr/local/etc/redis.conf.example redis.conf
>ee redis.conf
unixsocket /tmp/redis.sock

>service redis start

>openvassd
>greenbone-nvt-sync
>greenbone-scapdata-sync
>greenbone-certdata-sync
>openvasmd --rebuild --progress
>openvasmd --create-user=admin --role=Admin
>openvasmd --user=admin --new-password=admin

>service openvassd restart
#這個指令會有錯誤訊息,待查
#Unknown option --listen=127.0.0.1
#解法 /etc/rc.conf加入
#openvassd_flags=""

>service openvasmd restart
#重開機會開不起來
#log
#Setting GnuPG dir to '/var/lib/openvas/openvasmd/gnupg'
#Setting GnuPG dir failed: Invalid crypto engine
#目前找尋解決方法中
#可使用/usr/local/etc/rc.d/openvasmd start手動啟動

>openvasmd --rebuild --progress

>service gsad start


>pkg install texlive-texmf
#裝了也無法產出pdf檔
#目前找尋解決方法中
**pkg install tex-formats 補上pdflatex程式

2017年5月15日 星期一

masscan 網路掃描

安裝
pkg install masscan

使用
#掃描整個網段的80port(TCP)
masscan 10.10.1.0/24 -p80 -e em0 --router-ip 10.10.1.254

#掃描單一IP的所有port(TCP)
masscan 10.10.1.1 -p0-65535 -e em0 --router-ip 10.10.1.254

#掃描port(UDP)
masscan 10.10.1.1 -pU:123 -e em0 --router-ip 10.10.1.254

2015年10月16日 星期五

kernel: Limiting icmp unreach response from 299 to 200 packets/sec

/var/log/messages
Oct 15 09:38:32 machine kernel: Limiting icmp unreach response from 299 to 200 packets/sec

當出現以上訊息時,可能是RST攻擊,可以設定以下參數(預設為0)。

sysctl -w net.inet.tcp.blackhole=2
sysctl -w net.inet.udp.blackhole=1

然後在/etc/sysctl.conf加入
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1


2015年5月5日 星期二

snmp + mrtg

snmp

1.ee /etc/rc.conf加入
bsnmpd_enable="YES"

2./etc/rc.d/bsnmpd start


mrtg

1.cd /usr/ports/net-mgmt/mrtg
   make BATCH=yes install clean

2.ee /etc/rc.conf加入
mrtg_daemon_enable="YES"
mrtg_daemon_config="/usr/local/etc/mrtg/mrtg.cfg"

3.啟動mrtg
mrtg /usr/local/etc/mrtg/mrtg.cfg


index.htm

indexmaker -output=/home/www/mrtg/index.htm /usr/local/etc/mrtg/mrtg.cfg


2015年4月15日 星期三

dokuwiki安裝過程

1. 安裝
cd /usr/ports/www/dokuwiki
    make install clean

2.httpd.conf加入
Alias /dokuwiki /usr/local/www/dokuwiki
Directory "/usr/local/www/dokuwiki"
    Options FollowSymLinks
    AllowOverride ALL
    Require all granted
/Directory

3. 變更資料夾權限
chown -R www /usr/local/www/dokuwiki

4.開啟設定網頁
http://ip/dokuwiki/install.php

5.設定完成後
   rm /usr/local/www/dokuwiki/install.php
   chown -R root /usr/local/www/dokuwiki/conf

2015年3月18日 星期三

在 FreeBSD 10.1 上建置 vpn server

/usr/ports/net/mpd5
make install clean

edit /usr/local/etc/mpd5/mpd.conf

startup:

default:
        load pptp_server

pptp_server:
        set ippool add LANPOOL 10.10.1.10 10.10.1.50

        create bundle template VPN

        set iface disable on-demand
        set iface idle 0

        set iface enable proxy-arp
        set iface enable tcpmssfix

        set ipcp yes vjcomp

        set ipcp ranges 10.10.1.1/32 ippool LANPOOL

        set bundle enable compression

        set ccp yes mppc

        set mppc no e40
        set mppc yes e128

        set mppc yes stateless

        create link template VPNLINK pptp

        set link action bundle VPN

        set link enable multilink

        set link yes acfcomp protocomp

        set link no pap chap

        set link enable chap

        set link keep-alive 30 300

        set link mtu 1460

        set link enable incoming


edit /usr/local/etc/mpd5/mpd.secret

abcd 123456   //account password

edit /etc/rc.conf

gateway_enable="YES"

pf_enable="YES"
pf_rules="/etc/pf.conf"
pflog_enable="YES"
pflog_logfile="/var/log/pflog"

mpd_flags="-b"
mpd_enable="YES"


edit /etc/pf.conf

ext_if ="hn0"

table persist {10.10.1.0/24}

nat on $ext_if from to any -> ($ext_if)
pass in all
pass out all
#pass in quick inet from to any keep state

重新啟動之後,使用abcd及密碼123456撥接登入vpn server

2014年12月15日 星期一

freebsd with bandwidthd

1. cd /usr/ports/www/apache24
    make BATCH=yes install clean

2.cd /usr/ports/net-mgmt/bandwidthd
    make BATCH=yes install clean

3.ee /usr/local/etc/apache24/httpd.conf

LISTEN 8008

DocumentRoot "/usr/local/bandwidthd/htdocs"


4.mv /usr/local/etc/rc.d/bandwidthd.sh.sample /usr/local/etc/rc.d/bandwidthd
ee /usr/local/bandwidthd/etc/bandwidthd.conf

subnet 172.16.0.0/18

dev "bge1"

5.ee /etc/rc.conf
apache24_enable="YES"

6./usr/local/etc/rc.d/apache24 start
    /usr/local/etc/rc.d/bandwidthd start