Unknown's avatar

About Hojin

I am very happy to help somebody for whatever as much as I can.

Moving MySQL Database Folder

By default, MySQL database is stored on ubuntu on “/var/lib/mysql/” folder according to my.cnf. If you want to move the stored folder to another(e.g., /nsm/mysql/), you can refer the script below.

$ service mysql stop
$ cp -avrp /var/lib/mysql /nsm/
$ chown -R mysql:mysql /nsm/mysql/
$ vi /etc/mysql/my.cnf
– datadir=/var/lib/mysql
+ datadir=/nsm/mysql
$ service mysql start

If there is anything for restricting the MySQL database file or folder, you need to re-configure it such as SELinux or AppArmor(“Application Armor”).

$ vi /etc/apparmor.d/usr.sbin.mysqld
– /var/lib/mysql/ r,
– /var/lib/mysql/** rwk,
+ /nsm/mysql/ r,
+ /nsm/mysql/** rwk,
$ /etc/init.d/apparmor restart

Windows Event Log Setting

As you might know, Windows Event Log is not properly logged by default setting. Once you meet a computer incident, if you want to get valuable information from Windows, you need to adjust configuration. Here is a script I used.

auditpol /set /category:"Account Logon" /success:enable /failure:enable
auditpol /set /category:"Account Management" /success:enable /failure:enable
auditpol /set /category:"Detailed Tracking" /success:enable /failure:enable
auditpol /set /category:"DS Access" /success:enable /failure:enable
auditpol /set /category:"Logon/Logoff" /success:enable /failure:enable
auditpol /set /category:"Object Access" /success:enable /failure:disable
auditpol /set /category:"Policy Change" /success:enable /failure:enable
auditpol /set /category:"Privilege Use" /success:enable /failure:enable
auditpol /set /category:"System" /success:enable /failure:enable
auditpol /set /subcategory:"Filtering Platform Connection" /success:disable /failure:disable
auditpol /set /subcategory:"Filtering Platform Packet Drop" /success:disable /failure:disable

I disabled the failure of Object Access and regarding filtering platform, because these generates a lot of logs unnecessarily. Of course, if you afford to store these kind of logs, you can enable them.

 

Load Balancing on Syslog-ng

When you want to send logs to specific logging servers at least two more to be load balancing, you can use Syslog-ng with the configuration as below. Deciding server where you send a log is depended on the last digit number of the system uptime. Here is a sample Syslog-ng configuration file for aforementioned the load balance.

filter f_0 {
   match("[0-9]*[02468]$" value("SYSUPTIME"));
};

filter f_1 {
      match("[0-9]*[13579]$" value("SYSUPTIME"));
};

log { source(s_fw); filter(f_0); destination(d_redis0); };
log { source(s_fw); filter(f_1); destination(d_redis1); };

 

Forensically Sound Windows

I called “Forensically Sound Environment” as an operating system is good at logging or tracing for analysis to a specific case in terms of forensic or incident response. Here are some configurations to make forensically sound environment.

Prerequisite

  1. Sync date and time to localtime or UTC

Windows

Most of configurations are Windows artifacts. Of course, it’s included that application such as IIS, Windows Advanced Firewall ans so on, however we can’t get any evidence from them unless you set those configurations properly like forensically sound environment.

  1. EnablePrefetcher
  2. NtfsDisableLastAccessUpdate
  3. $LogFile
  4. Windows Recovery
  5. Minidump
  6. Windows Event Log
  7. WinRM service
  8. Event Tracing for Windows
  9. C:\> openfiles /local on
  10. Windows Advanced Firewall
  11. Application Log
    1. IIS
    2. Anti-Virus
    3. Adobe Reader

Linux

  1. Auditd
  2. iptables logging

Post Task

  1. Build MD5 white-list
  2. Logging remotely

I will describe about each title as above in more detail. And I’ll put the link on the title on this page. I hope that I want to make the list in question with you.

Create a local account without console logon

The goal of this manual is to assign a user to necessary privilege(s) to do the purpose. For instance, you can refer to this page when create an account for file copy, local script execution as well as ftp user.

1. Create a user as local account

  • GUI: lusrmgr.msc
  • CLI:
    • net user /ADD [username] [password]  /PASSWORDCHG:no
    • WMIC USERACCOUNT WHERE “Name='[username]'” SET PasswordExpires=FALSE

Windows Account Properties

2. The user is only included Users group

The user created just before is automatically a member of Users group. So we need to exclude the user in Users group. After that, add the user into a new group, which will be authorized to execute as a bactjob only.

  • GUI: lusrmgr.msc
  • CLI:
    1. net localgroup Users [username] /delete
    2. net localgroup CLIUsers /add
    3. net localgroup CLIUsers [username] /add

3. The user is not allowed to logon both locally and remotely

The new created group, CLIUsers, should not be allowed to log on both locally and remotely. Here is a way to check out.

Windows Local Security Policy

3.1 Locally

Check if the ‘CLIUsers’ group is allowed to log on locally. The ‘CLIUsers’ group should not be included in “Allow log on locally” policy.

  • GUI: secpol.msc / gpedit.msc
    [Computer Configuration –> Windows Settings –> Security Settings –> Local Policies –> User Rights Assignment –> Allow log on locally(로컬 로그온 허용)]

3.2 Remotely

Check if the ‘CLIUsers’ group is allowed on to log on through remote desktop services.

  • GUI: gpedit.msc
    The CLIUsers group should not be included in the remote logon right at [Computer Configuration –> Windows Settings –> Security Settings –> Local Policies –> User Rights Assignment –> Allow log on through Remote Desktop Services(원격 테스크톱 서비스를 통한 로그온 허용)]

Err Msg not allowed login

When you’re trying to logon on local console after the configuration as above, you can see the error message as below.

3.3 Allow “Log on as a batch job”

  • GUI: gpedit.msc
    Add “CLIUsers” group into “Log on as a batch job(일괄 작업으로 로그온)” at [Computer Configuration –> Windows Settings –> Security Settings –> Local Policies –> User Rights Assignment]

Now you can use the new account for a local service, such as task scheduler, in accordance with Principle of least privilege.

Case Study: Security Onion Server Disk Full

잘 동작하던 Security Onion(SO)가 갑지가 동작하지 않을 때 수 많은 이유가 있겠지만, HDD DISK가 가득차 동작하지 않는 경우라면 이 글이 도움될 수 있겠네요.

이 글을 읽기 전에 아래와 같은 명령어로 디스크 사이즈를 줄여보셨나요?! 적어도 필자는 별 효과가 없었습니다. 왜냐하면 일반적인 파일 문제가 아니라 sguil이 사용하는 MySQL의 securityonion_db에 엄청난 데이터가 쌓여있기 때문 입니다.

$ du -h –max-depth=1 /  (하위 폴더별 디스크 사용량)
$ truncate -s 0 /var/log/*log (모든 log 파일 내용 지우기)
$ find /var/log -type f -name ‘*.gz’ -exec rm {} \; (모든 gz 파일 삭제하기)
$ find / -size +2048M -ls (2GB 보다 큰 파일 찾기)

Sguil Database

SO 운영자가 아직 최적화(Optimizing)를 하지 않고 설치 시 기본 값으로만 SO를 운영할 경우 금방 DISK가 차버릴 수 있습니다. 로그 저장 능력과 관련해 기본값은 아래와 같이 90일로 설정되어 있었는데, 필자의 경우 설치 후 운영한지 이틀만에 DISK FULL 되었습니다. 그래서 /etc/nsm/securityonion.conf 에서 DYASTOKEEP 과 DAYSTOREPAIR를 각각 7일과 3일로 변경 했습니다. (우선은 운영을 해야 하겠기에..ㅠㅠ)

-DAYSTOKEEP=90
+DAYSTOKEEP=7
-DAYSTOREPAIR=7
+DAYSTOREPAIR=3

그런데 아직 위 옵션들이 적용되지 않았습니다. 그 이유는 이런 옵션들은 sguil-db-purge 에 의해서 참조되기 때문에, sguil-db-purge를 별도로 실행시켜줘야 합니다.

Network Packet Capture Files

캡쳐된 Raw 패킷은 분석할 때 유용하게 사용되지만, 네트워크 볼륨에 비래한 저장공간을 필요로 하기 때문에 관련된 옵션을 잘 파악하여 운영의 묘를 살려야 하겠습니다. 기본적으로 저장되는 곳은 /nsm/sensor_data/eth0/dailylogs/YYYY-MM-DD/snort.log.*  와 같은 패턴으로 tcpdump 파일이 기록됩니다. 아래 명령어들은 이와 같은 파일들이 기록되지 않도록 합니다.

$ sed -i ‘s|PCAP_ENABLED=”yes“|PCAP_ENABLED=”no“|g’ /etc/nsm/*/sensor.conf
$ sed -i ‘s|PCAP_AGENT_ENABLED=”yes“|PCAP_AGENT_ENABLED=”no“|g’ /etc/nsm/*/sensor.conf
$ nsm_sensor_ps-stop –only-http-agent
$ chmod 0 /usr/bin/netsniff-ng

 

Why NLA is more secure than other before?!

RDP 연결을 위해 서버에서 필요한 설정을 하다가 다음과 같은 옵션에 대해 궁금해졌다. “네트워크 수준 인증을 사용하여 원격 데스크톱을 실행하는 컴퓨터에서만 연결 허용” 더욱이 한글버전에서는 “권장”, 영문에서는 “more secure” 라고 추가설명을 하고 있다.

윈도우_원격데스크톱_옵션

“네트워크 수준 인증(Network Level Authentication, NLA)”이란 무엇일까?! 구글링 해보면, 특정 프로그램이 세션을 만들기 전에 CredSSP (Security Support Provider) 를 이용해 사용자 인증 정보를 서버에 전달하는 것이라고 한다.

저 옵션을 켜고 껏을 때 차이점이 도대체 뭔 말인지 감이 오질 않았는데 (이 글을 읽어보고 Windows Server 2008 R2: Why Use Network Level Authentication?) 이제야 알게 된것 같다. 일반적으로 세션을 만들기 전에도 사용자의 ID/PW을 얻기 위한 화면을 생성하게 되는데, 윈도우 같은 경우 csrss.exe 와 winlogon.exe 등 다수의 리소스가 동작하게 된다. 따라서 이러한 세션이 시작하기 전에 NLA가 사용자 정보를 서버에게 보내 정말 로그인을 원하는 사용자가 세션을 요청하는 것이라고 증명하는 과정이라 할 수 있겠다.

그 밖에 *.rdp 파일을 텍스트 편집기로 열어보면 옵션들이 보이는데, 아래 두 개의 옵션이 인증과 관련있어 보인다.

 

BurpSuite를 이용한 HTTPS 웹사이트 분석

BurpSuite 를 사용해 HTTPS 웹사이트를 분석할 경우, 몇 가지 작업을 통해 정상적인 분석이 가능했다.

PortSwigger CA 인증서 설치

웹브라우져가 https 주소의 웹서버에 접근할 때 BurpSuite는 자신이 해당 웹서버에 접속하여 서버로 부터 받은 암호화된 정보를 분석 후, 다시 자신의 인증서로 HTTPS 를 웹브라우져에게 전달한다.

이와 같은 이유로 클라이언트에는 BurpSuite 의 인증서가 “신뢰할 수 있는 루트 인증기관”에 설치되어 있어야 한다. 로컬에 설치된 인증서들을 certmgr.msc 통해서 확인할 수 있다.

Java Cryptography Extension(JCE) 설치

BurpSuite 인증서를 클라이언트에 설치 후 다시 접속해 보면 “Received fatal alert: handshake_failure” 이라는 에러 메시지를 만날 수 있다. 이 문제를 해결하기 위해서는 JCE를 업데이트 해야 한다. (적어도 나의 경우에는 그랬다.)

클라이언트에 설지된 Java의 버전과 같은 JCE를 다운로드 받은 후 (압축을 풀어) local_policy.jar, US_export_policy.jar 파일을 %JAVA_HOME%\lib\security\ 폴더에 복사하면 된다. BurpSuite를 재시작 해주는 것도 잊지 말자. 필자의 경우 해당 폴더의 경로는, C:\Program Files (x86)\Java\jre1.8.0_91\lib\security\ 와 같았다.

Zabbix-Agent Upgrade

오래된 Ubuntu 에서 zabbix-agent 를 설치하기 위해 단순히 apt-get install zabbix-agent 만 할경우 버전이 낮아 zabbix 서버와 통신을 하지 못하는 경우가 있다.

이럴경우 zabbix-agent 버전을 업그레이드 하기 위해서 apt-get update 후 재설치해서 되는 경우도 있지만 apt source 에도 낮은 버전만 바라보고 있는 경우가 있어, 이럴경우 아래와 같은 방법으로 해결할 수 있다.

Method 1

$ wget -e http_proxy=10.10.10.10:8080 http://repo.zabbix.com/zabbix/2.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.2-1+precise_all.deb
$ sudo dpkg -i zabbix-release_2.2-1+precise_all.deb
$ sudo apt-get update
$ sudo apt-get purge zabbix-agent
$ sudo apt-get install zabbix-agent

Method 2

$ add-apt-repository ppa:dottedmag/zabbix-agent
$ apt-get update
$ apt-get install zabbix-agent

RDP Installation via apt-get

To access a Ubuntu server via RDP, you should install or configure as below.

RDP

Server

$ apt-get install xrdp
$ apt-get install xfce4
$ vi /etc/xrdp/startwm.sh

#./etc/X11/Xsession
./usr/bin/startxfce4

$ /etc/init.d/xrdp restart

Client

C:/> mstsc /v:{the server ip address}