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

Raspberry Pi 3 64bit OS openSUSE: Install

2017-10-30: swap 추가, timezone 수정
{:.right-history}

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

이글은 5개 글타래로 구성되며, openSUSE 설치 및 사용에 대해 작성한다.

  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, Jupyter
  5. openSUSE: Build MongoDB 3.4.x
자세히 보기