Monitoring fail2ban

Monitoring fail2ban

Install

로그를 검사해 의심스런 IP 를 찾아 Firewall rule을 관리하기 어렵다 Fail2ban은 정규표현식을 사용해서 로그에서 의심스런 IP를 찾아 Firewall 등록할 수 있도록 해준다.

Fail2ban

로그를 검사해 의심스런 IP 를 찾아 Firewall rule에 등록해 관리하는 것은 어려운 과정이다. Fail2ban은 정규표현식을 사용해서 로그에서 의심스런 IP를 찾아 Firewall 등록 할 수 있도록 해준다.

설치

fail2baniptables 패키지와 함께 설치한다.

1
$ sudo apt install iptables fail2ban

그리고 systemctl 로 재대로 서비스가 시작되는지 확인해 본다.

1
2
$ sudo systemctl restart fail2ban.service    # 재시작
$ sudo systemctl status fail2ban.service # running 상태 확인

설정을 위해서 fail2ban 설정 파일인 fail2ban.conf, 그리고 jail 파일 jail.conf 파일을 .local 파일로 복사한 사용자 정의 파일에서 사용한다.

1
2
3
$ cd /etc/fail2ban
$ sudo cp fail2ban.conf fail2ban.local # 설정파일
$ sudo cp jail.conf jail.local # jail 설정

/etc/fail2ban 디렉토리

설치된 후 관련된 설정 파일은 /etc/fail2ban 디렉토리에 저장됩니다. 관련한 로그 기록은 /etc/logratate.d/fail2ban에 정의되어 /var/log/fail2ban.log 로 저장됩니다.

다음은 설정 디렉토리 구조

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ tree -L 2 fail2ban/
fail2ban/
├── action.d
│   ├── ...
│   ├── ufw.conf
│   └── xarf-login-attack.conf
├── fail2ban.conf
├── fail2ban.local
├── fail2ban.d
├── filter.d
│   ├── ...
│   ├── sshd.conf
│   └── xinetd-fail.conf
├── jail.conf
├── jail.d
│   └── defaults-debian.conf
├── jail.local
├── paths-common.conf
└── paths-debian.conf
  • jail.conf: jail 이라 불리는 모니터링할 대상에 대한 기본 옵션과 행위를 선언한다.
  • action.d/iptables-multiport.conf: fila2ban 이 jail에 맞게 거부(Ban)한 IP를 다루는 기본 액션이다.
  • fail2ban.local : fail2ban 주요 설정 파일
  • jail.local: jail 설정 파일
  • jaild.d/defaults-debian.conf: jail enable/disable
  • paths-common.conf: 로그 파일 경로
  • paths-debian.conf: 로그 파일 경로

설정

fail2ban은 jail 을 구성하고 jail의 filter 그리고 action으로 나뉘어 있다.

fail2ban.conf 구성

fail2ban.conf는 기본 구성 변수로 loggin, socket 그리고 PID 파일 등등이 설정된다. 별도의 파일로 Jail을 구성할 때 fail2ban.local 같은 이름을 사용하고 새로 설정되는 값은 기본 설정 값을 재정의 하게 된다.

단 같은 [default] 섹션이 존재하면 구성된 내용 적용이 잘 안된다.

다음 스크립을 사용하면 모둔 변수를 주석 처리하고 수정할 옵션만 복사해 준다.

1
sed 's/\(^[[:alpha:]]\)/# \1/' fail2ban.conf | sudo tee fail2ban.local 1&> /dev/null

fail2ban.local 파일은 다음과 같은 내용을 담을 것이다.

  • loglevel: The level of detail that Fail2ban’s logs provide can be set to 1 (error), 2 (warn), 3 (info), or 4 (debug).
  • logtarget: Logs actions into a specific file. The default value of /var/log/fail2ban.log puts all logging into the defined file. Alternately, you can change the value to STDOUT, which will output any data; STDERR, which will output any errors; SYSLOG, which is message-based logging; and FILE, which outputs to a file.
  • socket: The location of the socket file.
  • pidfile: The location of the PID file.

jail.conf

/etc/fail2ban/jail.conf 는 데몬, 서비스에 대한 jail을 구성한다. jail은 log를 읽어 불필요한 것을 찾아 낸다.
다음은 jail.conf에서 주석이 달린 jail.local을 생성해 준다.

1
sed 's/\(^[[:alpha:]]\)/# \1/' jail.conf | sudo tee jail.local 1&> /dev/null

If using CentOS or Fedora open jail.local and set the backend to systemd. This is not necessary on Debian 8, even though it is a SystemD system.

/etc/fail2ban/jail.local

1
backend = systemd

화이트리스트 IP

먼저 검출된 IP 중에 무시할 영역, 화이트리스트를 선언해 줍니다. 리스트는 ‘,’로 구분하고 서브넷 혹은 IP주소를 입력한다.

1
2
[DEFAULT]
ignoreip = 127.0.0.1/8 192.168.0.1/24

차단 시간과 재시도 횟수

bantime, findtime, maxretry 은 차단 시간에 대한 구성이다.

1
2
3
bantime = 2592000
findtime = 600
maxretry = 3
  • bantime: 검출된 IP가 접속 차단 시간을 초단위로 선언해 준다. -1 이면 영속적으로 밴 된다.
  • findtime: ban이 설정 전에 로그인 간격 시간
  • maxretry: 최대 횟수

https://arno0x0x.wordpress.com/2015/12/30/fail2ban-permanent-persistent-bans/

로컬 시스템의 이메일 주소를 sendmail -t user@email.com, replacing user@email.com with your email address.

이메일

fail2ban에 검출되는 jail이 있으면 이메일 설정에 따라 메일로 경고를 받을 수 있다.

  • destemail: The email address where you would like to receive the emails.
  • sendername: The name under which the email shows up.
  • sender: The email address from which Fail2ban will send emails.

그리고 action 설정을 조절할 필요가 있다, 이것은 ban 상황이 기준점에 닿으면 발생한다. 기본 액션 %(action_)s은 사용자만 ban 한다. action_mw 액션은 ban을 실행하고 WhoIS 리포트로 메일을 보내준다. action_mwl은 모든 로그까지 함께 보내준다.

You will also need to adjudst the action setting, which defines what actions occur when the threshold for ban is met. The default, %(action_)s, only bans the user. action_mw will ban and send an email with a WhoIs report; while action_mwl will ban and send an email with the WhoIs report and all relevant lines in the log file. This can also be changed on a jail-specific basis.

1
action = %(action_)s
1
$ sudo service fail2ban restart

각 서버스에 대한 Jail 설정

필터를 이용해 Jail을 만들어 의심스런 접근을 막아 보자. 앞서 복사한 jail.local 파일에는 주요 서비스가 모두 선언되어 있고 sshd 만 활성화 되어 있다.

Jail은 다음 같이 구성된다.

1
2
3
4
5
6
7
8
[ssh]

enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 6

  • enabled: Determines whether or not the filter is turned on.
  • port: The port Fail2ban should be referencing in regards to the service. If using the default port, then the service name can be placed here. If using a non-traditional port, this should be the port number. For example, if you moved your SSH port to 3456, you would replace ssh with 3456.
  • filter: The name of the file located in /etc/fail2ban/filter.d that contains the failregex information used to parse log files appropriately. The .conf suffix need not be included.
  • logpath: Gives the location of the service’s logs.
  • maxretry: Will override the global maxretry for the defined service. findtime and bantime can also be added.
    action: This can be added as an additional setting, if the default action is not suitable for the jail. Additional actions can be found in the action.d folder.

각 서비스에 대한 jail은 jail.d에 설정 파일을 구성해도 된다.

(1) sshd

Brute-force Attack과 같은 접근을 차단하는 필터로 로그에 아래와 유사한 패턴이 나오면 IP를 검출한다.

Jul 22 06:56:50 foo sshd[14984]: Failed password for invalid user a from xxx.xxx.xxx.xxx port 55452 ssh2

jail.config 혹은 jail.local 에서 기본으로 활성화 되어 있다.

(2) ssh-ddos

sshd-ddos Filter를 사용해 SSH Service를 Scanning하거나 telnet으로 접속할 떄 발생하는 Message를 검사하여 해당 IP의 접근을 차단할 수 있습니다.

이 Filter로 검출되는 /var/log/auth.log의 Message는 다음과 같습니다.

Jul 23 13:16:25 foo sshd[21989]: Did not receive identification string from xxx.xxx.xxx.xxx

Jail 설정을 위해서 다음과 같이 입력합니다.

1
2
[sshd-ddos]
enabled = true

혹은 $ sudo vi /etc/fail2ban/jail.d/sshd-ddos.conf

1
$ sudo service fail2ban restart

Failregrexs

다양한 필터를 사용할 수있다. 의심스런 동작을 Filter로 선언해서 사용하는데 해당 필터를 점검해야할 필요가 있다. 다음

1
$ sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf

이 필터를 사용자가 작성할 수 있는데 파이썬의 정규식을 사용해서 사용자 지정 필터를 작성한다.

access.log 필터 작성해 보기

nginx 로그를 대상으로 200 에러를 검출해 보자

1
91.134.232.57 - - [28/Nov/2016:07:30:23 +0900] "GET / HTTP/1.1" 200 1125 "http://hundej

123.143.201.75 - - [28/Nov/2016:17:29:18 +0900] “HEAD / HTTP/1.1” 200 0 “-“ “python-requests/2.10.0”

fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/nginx-test.conf

Ban 관리

fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE

Use iptables -L -n to find the rule name…
…then use fail2ban-client status to get the actual jail names.

룰 이름이 표시된다 f2b- 으로 시작하는 룰을 찾는다

그리고 fail2ban-status 는

fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE

HOW to fail2ban

basic usages

1
2
sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf

1
sudo iptables -L --line-numbers

Nginx

기본으로 /etc/fail2ban/jail.conf 에 [nginx-http-auth] jail이 하나 선언되어 있다.

[nginx-http-auth]

enabled = true
filter = nginx-http-auth
port = http,https
logpath = /var/log/nginx/error.log

nginx jail

nginx-noscript

웹 사이트에서 실행되고 침투할 수 있는 코드를 찾아 준다. php 등이 웹 사이트와 연동되지 않았다면 아래 제일을 추가해서 이런 임의의 실행코드 형식 실행을 방지할 수 있다

1
2
3
4
5
6
7
8
[nginx-noscript]

enabled = true
port = http,https
filter = nginx-noscript
logpath = /var/log/nginx/access.log
maxretry = 6

nginx-badbots

웹 요청에 악의적인 봇을 호출하는 것을 방지한다.

1
2
3
4
5
6
7
[nginx-badbots]

enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/nginx/access.log
maxretry = 2

filter

추가한 jail 이 동작할 필터를 작업해 주어야 한다. 필터는 /etc/fail2ban/filter.d 디렉토리에 있다.

nginx-http-auth.conf

기본으로 제공하는 nginx-http-auth.conf 필터에 하나를 더 추가해 준다. 아래는 사용자가 아이디와 비밀번호를 입력하지 않는 경우에 대해 필터한다. 아래의 no user/password 패턴을 추가한다.

1
2
3
4
5
6
7
[Definition]


failregex = ^ \[error\] \d+#\d+: \*\d+ user "\S+":? (password mismatch|was not found in ".*"), client: <HOST>, server: \S+, request: "\S+ \S+ HTTP/\d+\.\d+", host: "\S+"\s*$
^ \[error\] \d+#\d+: \*\d+ no user/password was provided for basic authentication, client: <HOST>, server: \S+, request: "\S+ \S+ HTTP/\d+\.\d+", host: "\S+"\s*$

ignoreregex =

nginx-badbots.conf

1
sudo cp apache-badbots.conf nginx-badbots.conf

nginx-noscript

[nginx-noscript] jail 은 다음 내용을 입력한다:

1
2
3
4
5
[Definition]

failregex = ^<HOST> -.*GET.*(\.php|\.asp|\.exe|\.pl|\.cgi|\.scgi)

ignoreregex =

nginx-nohome

1
2
3
4
5
[Definition]

failregex = ^<HOST> -.*GET .*/~.*

ignoreregex =

nginx-noproxy

1
2
3
4
5
[Definition]

failregex = ^<HOST> -.*GET http.*

ignoreregex =

Jail 실행 확인

1
2
3
4
$ sudo fail2ban-client status
Status
|- Number of jail: 6
`- Jail list: nginx-noproxy, nginx-noscript, nginx-nohome, nginx-badbots, ssh-ddos, ssh

그리고 iptable의 서비스로 방화벽 규칙에 fail2ban 규칙이 동작중인지 확인한다.

1
2
3
4
5
6
7
8
9
10
11
12
 $ sudo iptables -S
...

-A fail2ban-nginx-badbots -j RETURN
-A fail2ban-nginx-nohome -j RETURN
-A fail2ban-nginx-noproxy -j RETURN
-A fail2ban-nginx-noscript -j RETURN
-A fail2ban-ssh -j RETURN
-A fail2ban-ssh-ddos -j RETURN

...

그리고 fail2ban 의 jail 실행 상태를 자세히 보고 싶므면 status 뒤에 jail 이름을 주면 된다.

1
2
3
4
5
6
7
8
9
10
$ sudo fail2ban-client status nginx-badbots
Status for the jail: nginx-badbots
|- filter
| |- File list: /var/log/nginx/access.log
| |- Currently failed: 0
| `- Total failed: 0
`- action
|- Currently banned: 0
| `- IP list:
`- Total banned: 0

Testing

의심스런 동작을 Filter로 선언해서 사용하는데 해당 필터를 점검해야할 필요가 있다. 다음

1
$ sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf

Ban 관리

nginx 인증 요구시 잘못된 인증을 시도하면 fail2ban 규칙에 따라 접근이 금지당한다. 그리고 jail 규칙이 잘 적용 됐는지 결과를 다음 같이 확인할 수 있다:

1
2
3
4
5
6
7
8
9
10
11
$ sudo fail2ban-client status nginx-http-auth
Output
Status for the jail: nginx-http-auth
|- filter
| |- File list: /var/log/nginx/error.log
| |- Currently failed: 0
| \- Total failed: 12
\- action
|- Currently banned: 1
| \- IP list: 111.111.111.111
\- Total banned: 1

인증 규칙에 어긋나는 접근을 시도한 IP인 111.111.111.111을 확인 할 수 잇다.
금지된 IP는 해당 jail을 이용해 다음 같이 해제할 수 있다.

1
$ sudo fail2ban-client set nginx-http-auth unbanip 111.111.111.111

nginx-req-limit

http://blog.ricardomacas.com/index.php?controller=post&action=view&id_post=3

fail2squared

https://supine.com/posts/2012/08/fail2ban-monitoring-itself-recursively/

TO COMPLETELY FLUSH THE FAIL2BAN LOG FILE AND CLEAR OUR BLACKLIST FILE

sudo service fail2ban stop
sudo truncate -s 0 /var/log/fail2ban.log
sudo truncate -s 0 /etc/fail2ban/ip.blacklist
sudo rm /var/lib/fail2ban/fail2ban.sqlite3
sudo service fail2ban restart

https://ubuntu101.co.za/security/fail2ban/fail2ban-persistent-bans-ubuntu/

sqlite3

fail2ban.conf file, I found the following:

1
dbfile = /var/lib/fail2ban/fail2ban.sqlite3

So, I did a little research to try to find out how access the database.

To open or connect to the database:

1
$ sqlite3 /var/lib/fail2ban/fail2ban.sqlite3

To list all the tables in the database:

1
2
sqlite> .tables
bans fail2banDb jails logs

To query a table:

1
sqlite> SELECT * FROM logs;

Another table:

sqlite> SELECT * FROM bans;

To disconnect from the database:

sqlite> .quit

참조

참조: https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-fail2ban-on-debian-7

fail2ban log

fail2ban log

fail2ban 로그는 아래 형태로

1
2
3
4
5
6
7
8
9
2016-08-28 12:35:56,163 fail2ban.actions[860]: WARNING [ssh] Ban 103.237.147.19
2016-08-28 12:36:09,215 fail2ban.actions[860]: WARNING [ssh] Ban 115.248.186.3
2016-08-28 17:39:47,806 fail2ban.actions[860]: WARNING [ssh] Ban 117.3.120.94
2016-08-28 23:06:21,291 fail2ban.actions[860]: WARNING [ssh] Ban 155.94.163.64
2016-08-29 19:50:51,400 fail2ban.actions[860]: WARNING [ssh] Ban 182.75.249.110
2016-08-31 14:26:54,093 fail2ban.actions[860]: WARNING [ssh] Ban 103.207.36.36
2016-09-01 02:23:23,790 fail2ban.actions[860]: WARNING [ssh] Ban 45.32.60.93
2016-09-01 17:44:35,854 fail2ban.filter [860]: WARNING Determined IP using DNS Lookup: 61-216-182-218.hinet-ip.hinet.net = ['61.216.182.218']
2016-09-01 17:47:18,004 fail2ban.actions[860]: WARNING [ssh] Ban 61.216.182.218

awk 이용 ip 주소 추출

awk 를 사용해서 로그에서 ip주소를 추출해 보자. 로그 내용에서 ‘Ban’을 포함한 줄을 만나면 $NF 변수에 각 컨럼을 저장한다.

1
2
3
4
5
$sudo awk '($(NF-1) = /Ban/){print $NF}' /var/log/fail2ban.log
103.237.147.19
115.248.186.3
117.3.120.94

IP주소를 정렬

1
2
3
4
$sudo awk '($(NF-1) = /Ban/){print $NF}' /var/log/fail2ban.log | sort | uniq -c | sort -n
1 103.207.36.36
1 103.237.147.19
1 115.248.186.3
  • 각 거부당한 IP 주소는 최대 실패 횟수 이후 ban 하므로 30회 이상의 시도가 있을

모든 백업 로그에서 IP 주소 추출

백업된 로그 파일을 모두 사용하려면 zgrep 명령을 사용해도 좋다

1
$sudo zgrep -h "Ban " /var/log/fail2ban.log* | awk '{print $NF}' | sort | uniq -c | sort -n

다음은 아주 위험한 서브넷을 출력한다.

1
2
3
4
5
6
7
8
9
10
11
$sudo zgrep -h "Ban " /var/log/fail2ban.log* | awk '{print $NF}' | awk -F\. '{print $1"."$2"."}' | sort | uniq -c  | sort -n | tail
2 222.186.
3 111.74.
3 116.100.
3 182.100.
3 195.154.
3 42.117.
7 115.239.
8 91.224.
14 103.207.
39 221.229.
1
2
3
4
5
6
$sudo zgrep -c 221.229 /var/log/fail2ban.log*
/var/log/fail2ban.log:0
/var/log/fail2ban.log.1:2
/var/log/fail2ban.log.2.gz:0
/var/log/fail2ban.log.3.gz:2
/var/log/fail2ban.log.4.gz:68

전체 로그에 순위 매기기

1
2
3
4
5
zcat /var/log/auth.log* | grep 'Failed password' | grep sshd | awk '{print $1,$2}' | sort -k 1,1M -k 2n | uniq -c

161 Mar 20
202 Mar 21

참조
Multiple log file

http://serverfault.com/questions/486301/how-to-set-up-fail2ban-to-read-multi-log-in-a-jail

Raspberry Pi 3에서 Opensuse LEAP 설치후 10가지 작업

Raspberry Pi 3에서 Opensuse LEAP 설치후 10가지 작업

jeos가 아닌 E20, LXQT 같은 데스크탑을 설치후 할 일을 정리했다.

Install Gnome Tweak Tool & dconf editor

By default GNOME 3 settings and options are looking good but if you want make your desktop more beautiful. Better you can install Gnome Tweak Tool & dconf editor which will give lots of cool options to make your desktop more beautiful which was not there in GNOME Application.

Install Icon theme

packman repository

라이센스와 특허 문제로 몇몇 중요한 저장소가 빠져서 배포되고 있다. opensuse 커뮤니티에서 이런 패키지를 제공하는 packman 저장소를 운영하고 있다. packman은 4가지 저장소 이루어저 있다.

  • Essensials: 오디오/비디오 앱을 위한 코덱
  • Multimedia: 멀티미디어 관련 앱
  • Extra: 멀티미디어 이외의 앱과 네트워크 관련
  • Games: 게임 패키지

Packman repository 활성화

1
~> sudo zypper addrepo http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Leap_42.3/ Packman-Repository

혹은

1
~> sudo zypper ar -f -n packman http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Leap_42.3/ packman

Tumbleweed [^4]

1
~> sudo zypper ar -p 1 -f -n packman http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/ packman

그리고 저장소 정보를 갱신한다.

1
~> sudo zypper ref

이 저장소를 지우려면

1
sudo zypper lr -d

해당 저장소 번로를 zypper rr [no] 명령으로 삭제한다.

1
sudo zypper rr 3

Media applications [^5]

vlc 설치

1
~> sudo zypper install vlc vlc-codecs

Transcode 혹은 비디오 변환작업을 하면 Hanbrake 가 적절한다.

1
~>sudo zypper install handbrake-cli handbrake-gtk

Install Media Codecs

H264/AVC streams support on your PC: [^4]

1
~> sudo zypper install x264 libx265-130 libx264-148

k3b-codecs [^5]

ffmpeg 와 lame 설치

1
~> sudo zypper install ffmpeg  lame

GStreamer 플러그인 설치

1
~> sudo zypper install gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-plugins-ugly-orig-addon gstreamer-plugins-libav

Chrome

Install Chrome [^5]

sudo zypper in chromium

OpenSUSE comes with Firefox as the default browser. But since Firefox isn’t capable of playing restricted media such as Netflix, I recommend installing Chrome. This takes some extra work. First you need to import the trusted key from Google. Open the terminal app and run the ‘wget’ command to download the key:

wget https://dl.google.com/linux/linux_signing_key.pub

Then import the key:

sudo rpm –import linux_signing_key.pub

Now head over to the Google Chrome website and download the 64 bit .rpm file. Once downloaded run the following command to install the browser:

sudo zypper install /PATH_OF_GOOGLE_CHROME.rpm

yast2 모듈

Leap 42.3 에는 yast -l 로 모듈을 확인해 bootloader, checkmedia
disk
firewall
host
inst_release_notes
keyboard
lan
language
proxy
remote
repositories
security
services-manager
sw_single, timezone, users, view_anymsg

추가적인 yast2 모듈을 설치하기 위해 아래 같이 검색할 수 있다.

1
sudo zypper search yast2-

VLC is one of the best multimedia players out there. It’s free and open source. You can install it via:

sudo zypper in vlc
you are a gamer, then you may probably want to install Steam:

sudo zypper in steam

Dropbox is probably the most famous solution on Linux desktops. You can install it using:

sudo zypper in dropbox

참고

[^1]: System Upgrade
[^2]: net-tools deprecated
[^4]: Things to do after installing opensuse
[^5]: 8 things to do after Opensue

Rasberry Pi EEG

Raspberry Pi로 구현하는 EEG

Electroencepharogram, EEG는 머리에 부착한 적극등에 의해 뇌의 활동 상태를 측정하는 기술이다.

머리의 대뇌피질에 전극을 연결해 뇌파를 측정하면 델타 -δ파(0.2 ~ 3.99 Hz), 쎄타 -θ파(4 ~ 7.99 Hz), 알파 -α파(8 ~ 12.99 Hz), 베타 -β파(13 ~ 29.99 Hz), 감마- g파(30~50 Hz) 파동으로 구분할 수 있다.

Raspberry Pi에서 EEG를 시현한 사례도 많이 제공되고 있다.

Neosky Mindwave

100€ 선에서 Neurosky Mindwave 제품같은 저렴한 EEG 헤드셋을 이용할 수 있다.

그림. Nerosky Mindwave EEG

다음은 유튜브에 공개된 Neurosky Mindwave를 사용한 시연 동영상이다:

Mind control with Raspberry Pi: Neurosky Mindwave

Mindwave

헤드셋과 Bluetooth dongle로 구성되어 있어서, 라즈베리파이에서 USB 장치 연결을 하고 dmesg로 장치 인식을 확인할 수 있다.
그리고 Mindwave용 Python라이브러리를 사용해 EEG 신호를 측정할 수 있다.

mindwave-python 라이브러리

파이썬 Mindwave 라이브러리를 사용할 수 있다.

DiY EEG circuit

EEG 세트를 자작으로 구현해 볼 수 있다.

참고

  1. Raspberry Pi mindcontrol! Neurosky mindwave as simple EEG interface
  2. 뇌파의 개요

Ubuntu/시스템 전원관리

Ubuntu - 시스템 전원관리

우분투 시스템을 명령으로 잠자기, 깨우기가 가능하다. 컴퓨터의 BIOS에서 Wake On Lan이 활성화 되어야한다.

WakeOnLan

wakeonlan을 활성화 하려면 이더넷 인터페이스를 화인한다.

1
2
3
4
5
6
7
8
9
$ ifconfig
enp5s0 Link encap:Ethernet HWaddr 0f:1a:92:51:70:a9
inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe20::6595:e3fd:ad6:10f1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:85121 errors:0 dropped:0 overruns:0 frame:0
TX packets:11677 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25916710 (25.9 MB) TX bytes:1481803 (1.4 MB)
자세히 보기

Raspberry Pi 3 64bit OS openSUSE: Build MongoDB 3.4

Raspberry Pi 3 64bit OS openSUSE 는 이글은 4개 글타래로 구성되며, openSUSE 설치 및 사용에 대해 작성한다.

Opensuse 에서 Raspberry Pi 3를 위한 64bit OS openSESE Leap 42.2 을 제공하고 있다.

  1. Install 64bit openSUSE Leap 42.2 / JeOS
  2. openSUSE: Managing Service daemon
  3. openSUSE: Basic OS Security for Server
  4. Install & Configuration - Nginx, Node JS
  5. Build MongoDB 3.4.x
자세히 보기

Raspberry Pi 3 64bit OS openSUSE: Nginx, Node JS, Jupyter

Raspberry Pi 3 64bit OS openSUSE 는 이글은 5개 글타래로 구성되며, openSUSE 설치, 개발도구 구성 및 서버 구축 사용에 대해 작성한다.

Opensuse 에서 Raspberry Pi 3를 위한 64bit OS openSESE Leap 42.2 을 제공하고 있다.

  1. Install 64bit openSUSE Leap 42.3 / JeOS
  2. openSUSE: Managing Service daemon
  3. openSUSE: Basic OS Security for Server
  4. Install & Configuration - Nginx, Node JS, Jupyter
  5. Build MongoDB 3.4.x
자세히 보기

Raspberry Pi 3 64bit OS openSUSE: Basic Security

Raspberry Pi 3 64bit OS openSUSE 는 이글은 3개 글타래로 구성되며, openSUSE 설치 및 사용에 대해 작성한다.

Opensuse 에서 Raspberry Pi 3를 위한 64bit OS openSESE Leap 42.3 을 제공하고 있다.

  1. Install 64bit openSUSE Leap 42.3 / JeOS
  2. openSUSE: Managing Service daemon
  3. openSUSE: Basic OS Security for Server
  4. Install & Configuration - Nginx, Node JS
  5. Build MongoDB 3.4.x
자세히 보기

Raspberry Pi 3 64bit OS openSUSE: Service 관리

Raspberry Pi 3 64bit OS openSUSE 는 이글은 3개 글타래로 구성되며, openSUSE 설치 및 사용에 대해 작성한다.

Opensuse 에서 Raspberry Pi 3를 위한 64bit OS openSESE Leap 42.3 을 제공하고 있다.

  1. Install 64bit openSUSE Leap 42.3 / JeOS
  2. openSUSE: Managing Service daemon
  3. openSUSE: Basic OS Security for Server
  4. Install & Configuration - Nginx, Node JS
  5. Build MongoDB 3.4.x

openSUSE: Basic OS Security for Server

openSUSE는 systemd 를 사용한 서비스/데몬 시작/종료/활성화/비활성화 작업을 할 수 있다. 서비스에 대한 작업은 systemctl CLI 혹은 YaST에서 가능하다.

yast

openSUSE는 yast 로 서비스 데몬도 설치/실행/멈춤 을 할 수 있다.

{:width=”640”}

서비스는
{:width=”640”}

systemd

https://doc.opensuse.org/documentation/leap/reference/html/book.opensuse.reference/cha.systemd.html

https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal

1
systemctl list-unit-files --type=service #현재 사용 가능한 모든 서비스

이 작업은

1
2
3
4
5
6
7
systemctl stop SuSEfirewall2
systemctl disable SuSEfirewall2
zypper in ufw
ufw default deny
ufw enable
systemctl enable ufw
systemctl start ufw

ssmtp

sSMTP is a simple MTA to deliver mail from a computer to a mail hub (SMTP server). sSMTP is simple and lightweight, there are no daemons or anything hogging up CPU; Just sSMTP. Unlike Exim4, sSMTP does not receive mail, expand aliases, or manage a queue.

https://wiki.debian.org/sSMTP

42.3, 15.0 에 ssmtp가 포함되지 않았다.

https://build.opensuse.org/package/binaries/home:jloehel/ssmtp/openSUSE_Factory_ARM

mail utitlity

1
$ sudo zypper install mail

Then try to send email from command line with:

1
$ echo "Message Body" | mail -s "Message Subject" receiver@example.com

참조

[^1]: systemd: Enable/Disable Services

Raspberry Pi 3 64bit OS openSUSE: Basic Security

Raspberry Pi 3 64bit OS openSUSE 는 이글은 3개 글타래로 구성되며, openSUSE 설치 및 사용에 대해 작성한다.

Opensuse 에서 Raspberry Pi 3를 위한 64bit OS openSESE Leap 42.3 을 제공하고 있다.

  1. Install 64bit openSUSE Leap 42.3 / JeOS
  2. openSUSE: Managing Service daemon
  3. openSUSE: Basic OS Security for Server
  4. Install & Configuration - Nginx, Node JS
  5. Build MongoDB 3.4.x

openSUSE: Basic OS Security for Server

이전 글에서 라즈베리파이 3에 설치한 64bit OS openSUSE LEAP / JeOS를 서버 구성을 위해서 보안 설정을 한다. 이 글은 다음 세가지 내용을 포함하고 있다.

  • ssh와 sshd 설정
  • 방화벽 설정: YaST Firewall 대비 ufw 설치
  • Fail2ban 설치 및 설정

sshd_config

ssh 사용시

sshd securities

방화벽 설정

openSUSE는 SuSEfirewall2 가 기본으로 제공되어 서비스를 활성화 하면 사용할 수 있다. 아직 익숙치 않아서 SuSEFirewall2 을 우분투/데비안에서 익숙한 ufw 를 설치해 사용하겠다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Basic Syntax:
yast2 firewall interactive
yast2 firewall <command> [verbose] [options]
yast2 firewall help
yast2 firewall longhelp
yast2 firewall xmlhelp
yast2 firewall <command> help

Commands:
broadcast Broadcast packet settings
disable Disables firewall
enable Enables firewall
interfaces Network interfaces configuration
logging Logging settings
masqredirect Redirect requests to masqueraded IP
masquerade Masquerading settings
services Allowed services, ports, and protocols
startup Start-up settings
summary Firewall configuration summary
zones Known firewall zones

먼저 SuSEfirewall2 를 멈추고 비활성화 한다.

1
sudo yast firewall disable
1
2
systemctl stop SuSEfirewall2
systemctl disable SuSEfirewall2

그리고 ufw를 설치하고

1
zypper in ufw
1
2
3
4
ufw default deny
ufw enable
systemctl enable ufw
systemctl start ufw

Fail2ban

rsyslog 를 설치한다.

https://en.opensuse.org/SDB:SSH_systematic_attack_protection

https://www.howtoforge.com/fail2ban_opensuse10.3

ssh

ufw

fail2ban

zypper in fail2ban

참조

OpenSSH Public Key Authentication

https://doc.opensuse.org/documentation/leap/security/html/book.security/cha.security.firewall.html