Hacker Lab

Gestion des logs


Les serveurs (ssh, Apache, nginx) et les services (iptables) génèrent des logs.

Il est important pour un administrateur de savoir:

  • ou ces logs sont enregistés
  • quel est leur format
  • quelle quantité de logs est gardée, et ainsi éviter de saturer les disques
  • comment les aggréger pour en extraire des informations pertinentes
  • prendre des décisions basées sur ces logs


    Board pour l'atelier: https://webwhiteboard.com/board/XCK2lJx3gNfacE6EXRpqB23y65rrkJeZ/

1 / 19 - Apache
1

Fichiers de log

Un serveur web Apache, utilise deux fichiers de logs :
~ apache access log : access
~ apache error log : error_log


Répertoires

Sur un serveur RHEL / Red Hat / CentOS / Fedora Linux Apache les logs sont en :

/var/log/httpd/ 


Sur un serveur Debian / Ubuntu Linux Apache les logs sont en :

/var/log/apache2/ 



Logs

Fichier servi normalement: access, code 200

192.168.2.20 - - [28/Jul/2006:10:27:10 -0300] "GET /cgi-bin/try/ HTTP/1.0" 200 3395 
127.0.0.1 - - [28/Jul/2006:10:22:04 -0300] "GET / HTTP/1.0" 200 2216 


Fichier non servi: access, code 4xx

127.0.0.1 - - [28/Jul/2006:10:27:32 -0300] "GET /hidden/ HTTP/1.0" 404 7218 

400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
...


Erreur dans la requête: error_log

[Fri Dec 16 01:46:23 2005] [error] [client 1.2.3.4] Directory index forbidden by rule: /home/test/ 
[Fri Dec 16 01:54:34 2005] [error] [client 1.2.3.4] Directory index forbidden by rule: /apache/web-data/test2 
[Fri Dec 16 02:25:55 2005] [error] [client 1.2.3.4] Client sent malformed Host header 
[Mon Dec 19 23:02:01 2005] [error] [client 1.2.3.4] user test: authentication failure for "/~dcid/test1": Password Mismatch 


Status du serveur: error_log

** Normal (v2.x) 
[Sat Aug 12 04:05:51 2006] [notice] Apache/1.3.11 (Unix) mod_perl/1.21 configured -- resuming normal operations 
[Thu Jun 22 14:20:55 2006] [notice] Digest: generating secret for digest authentication ... 
[Thu Jun 22 14:20:55 2006] [notice] Digest: done 
[Thu Jun 22 14:20:55 2006] [notice] Apache/2.0.46 (Red Hat) DAV/2 configured -- resuming normal operations 

** Restart by HUP signal (optional suEXEC) 
[Sat Aug 12 04:05:49 2006] [notice] SIGHUP received.  Attempting to restart 
[Sat Aug 12 04:05:51 2006] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/sbin/suexec) 

** after 'unclean' shutdown (left over PID file) 
[Sat Jun 24 09:06:22 2006] [warn] pid file /opt/CA/BrightStorARCserve/httpd/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? 
[Sat Jun 24 09:06:23 2006] [notice] Apache/2.0.46 (Red Hat) DAV/2 configured -- resuming normal operations 
[Sat Jun 24 09:06:22 2006] [notice] Digest: generating secret for digest authentication ... 
[Sat Jun 24 09:06:22 2006] [notice] Digest: done 

** shutdown by TERM signal 
[Thu Jun 22 11:35:48 2006] [notice] caught SIGTERM, shutting down 

** memory short 
[Tue Mar 08 10:34:31 2005] [error] (11)Resource temporarily unavailable: fork: Unable to fork new process 
2 / 19 - Apache
1


Connecte toi à splunk: http://splunk.yoloctf.org

login: admin
password: admin123456

Splunk Help: https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchTutorial/NavigatingSplunk


Importer des données

Format d'horodatage: %d/%b/%Y:%H:%M:%S
Help: https://docs.splunk.com/Documentation/Splunk/9.1.1/Data/Configuretimestamprecognition?ref=hk


Extraction des champs
Séparation par des Espaces
ip remote_log_name userid date timezone request_method path request_version status length referrer user_agent session_id generation_time_micro virtual_host

Regex:
"(?P.?) (?P.?) (?P.?) \[(?P.?)(?= ) (?P.?)\] \"(?P.?) (?P.?)(?P HTTP/.)?\" (?P.?) (?P.?) \"(?P.?)\" \"(?P.?)\" (?P.?) (?P.?) (?P.*)"g

Démarrez votre serveur dédié en cliquant sur [Start server].


Server status : stopped


3 / 19 - Apache 01
1

Adresse IP la plus présente

4 / 19 - Apache 02
1

Nombre de citation de l'IP : 50.16.19.13

5 / 19 - Apache 03
1

Nombre d'évènements GET sur fichiers robots.txt

host=* GET robots.txt 
6 / 19 - Apache 04
1

Nombre d'évènements en 200 Ok

7 / 19 - Apache 05
1

Les 3 status les moins fréquents au format x,x,x

8 / 19 - Apache 06
1

Nombre d'évènements en 404


IP ayant le plus d'évènements en 404

9 / 19 - Nginx
1

Importe le fichier nginx_logs dans splunk

10 / 19 - Nginx 01
1

Nombre d'évènements

11 / 19 - Nginx 02
1

Status le plus présent

Hypothèses ?

12 / 19 - Nginx 03
1

User agent des requètes en 404 (Partie avant le /)

Conclusion ?

13 / 19 - OpenSSH
1

Importe le fichier openssh.log dans splunk

14 / 19 - OpenSSH 01
1

Nombre d'évènements

15 / 19 - OpenSSH 02
1

Nombre d'authentication failure

16 / 19 - OpenSSH 03
1

En bas à gauche [+Extraction de nouveaux champs] Ajouter rhost et user
User ayant le plus grand nombre d'authentication failure

17 / 19 - OpenSSH 04
1

IP source du plus grand nombre d'authentication failure

18 / 19 - Proxifier
1

Importe le fichier proxifier.log dans splunk

19 / 19 - Waf
1

Importe le fichier waf-access.log dans splunk
Le format est de type json