notas:seguridad
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previaÚltima revisiónAmbos lados, revisión siguiente | ||
notas:seguridad [2011/07/12 13:54] – [Other useful examples] cayu | notas:seguridad [2015/01/21 20:25] – [Seguridad] cayu | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
====== Seguridad ====== | ====== Seguridad ====== | ||
+ | * [[notas: | ||
+ | ===== Notas ===== | ||
+ | Notas cortas de seguridad e inseguridad informática que me sirvieron en mi trabajo y algunos aspectos legales. | ||
+ | === Linux Auditd === | ||
+ | * [[notas: | ||
+ | * [[notas: | ||
+ | === Legales === | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | === Exploits === | ||
+ | Exploits útiles cuando vas a un lugar donde no saben el password de root | ||
- | Notas cortas de seguridad | + | {{:notas:seguridad: |
- | ===== Understanding Bash fork() bomb ~ :(){ :|:& | + | {{:notas: |
- | **Q.** Can you explain following bash code or bash fork() bomb? | + | {{:notas:seguridad:mempodipper.c.gz|}} Escalada de privilegios remota con / |
- | :(){ :|:& };: | + | |
- | **A.** This is a bash function. It gets called recursively (recursive function). This is most horrible code for any Unix / Linux box. It is often used by sys admin to test user processes limitations (Linux process limits can be configured via / | + | {{: |
- | Once a successful fork bomb has been activated in a system it may not be possible to resume normal operation without rebooting, as the only solution to a fork bomb is to destroy all instances of it. | + | {{:notas:seguridad: |
- | [Warning examples may crash your computer] WARNING! These examples may crash your computer if executed. | + | |
- | Understanding :(){ :|:& };: fork() bomb code | + | |
- | :() - It is a function name. It accepts no arguments at all. Generally, bash function is defined as follows: | + | === Bombas lógicas === |
- | + | * [[notas:seguridad:Understanding Bash fork() bomb]] | |
- | <code bash> | + | * [[notas:seguridad:How to: Prevent a fork bomb by limiting user process]] |
- | foo(){ | + | ==== Prevenir fingerprints |
- | | + | Como ayudar a que los fingerprint que realizen nuestros atacantes sean un poco menos exactos, configurar las sysctl de nuestro sistema de la siguiente manera: |
- | echo '' | + | |
- | # | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | fork() bomb is defined as follows: | + | |
- | + | ||
- | <code bash> | + | |
- | :(){ | + | |
- | : | + | |
- | };: | + | |
- | </ | + | |
- | ** | + | |
- | :|:** - Next it call itself using programming technique called recursion and pipes the output | + | |
- | + | ||
- | **&** - Puts the function call in the background so child cannot die at all and start eating system resources. | + | |
- | + | ||
- | **;** - Terminate the function definition | + | |
- | + | ||
- | **:** - Call (run) the function aka set the fork() bomb. | + | |
- | + | ||
- | Here is more human readable code: | + | |
- | + | ||
- | <code bash> | + | |
- | bomb() { | + | |
- | bomb | bomb & | + | |
- | }; bomb | + | |
- | </ | + | |
- | + | ||
- | Properly configured Linux / UNIX box should not go down when fork() bomb sets off. | + | |
- | + | ||
- | ==== Extra ==== | + | |
- | + | ||
- | Perl exmaple: | + | |
- | + | ||
- | <code perl> | + | |
- | perl -e "fork while fork" & | + | |
- | </ | + | |
- | + | ||
- | Python example: | + | |
- | + | ||
- | <code python> | + | |
- | import os | + | |
- | while(1): | + | |
- | os.fork() | + | |
- | </ | + | |
- | + | ||
- | Windows XP / Vista bat file example: | + | |
< | < | ||
- | :bomb | + | net.ipv4.ip_default_ttl = 128 |
- | start %0 | + | net.ipv4.tcp_timestamps = 0 |
- | goto bomb | + | net.ipv4.tcp_window_scaling = 0 |
- | </ | + | net.ipv4.conf.all.accept_redirects = 0 |
+ | net.ipv4.conf.all.send_redirects = 0 | ||
+ | net.ipv4.icmp_echo_ignore_all = 1 | ||
- | UNIX style for Windows: | + | # Enable IP spoofing protection |
- | + | net.ipv4.conf.all.rp_filter=1 | |
- | < | + | # Disable IP source routing |
- | %0|%0 | + | net.ipv4.conf.all.accept_source_route=0 |
+ | # Ignoring broadcasts request | ||
+ | net.ipv4.icmp_echo_ignore_broadcasts=1 | ||
+ | net.ipv4.icmp_ignore_bogus_error_responses=1 | ||
+ | # Make sure spoofed packets get logged | ||
+ | net.ipv4.conf.all.log_martians = 1 | ||
+ | net.ipv4.conf.default.log_martians = 1 | ||
</ | </ | ||
- | + | ==== Conocer que procesos bloquean tal cosa ==== | |
- | C program example: | + | |
- | + | ||
- | <code c> | + | |
- | #include | + | |
- | int main() { | + | |
- | </ | + | |
- | + | ||
- | Plz note that the fork bomb is a form of denial of service, so don’t run on production or unauthorized system. | + | |
- | + | ||
- | + | ||
- | ==== Fuente | + | |
- | + | ||
- | + | ||
- | http:// | + | |
- | + | ||
- | + | ||
- | ===== How to: Prevent a fork bomb by limiting user process ===== | + | |
- | + | ||
- | Limiting user processes is important for running a stable system. To limit user process just add user name or group or all users to **/ | + | |
- | + | ||
- | + | ||
- | ==== Understanding / | + | |
- | + | ||
- | + | ||
- | Each line describes a limit for a user in the form: | + | |
- | < | + | |
- | Where: | + | |
- | + | ||
- | + | ||
- | * **domain** can be: | + | |
- | * an user name | + | |
- | * a group name, with @group syntax | + | |
- | * the wildcard *, for default entry | + | |
- | * the wildcard %, can be also used with %group syntax, for maxlogin limit | + | |
- | * **type** can have the two values: | + | |
- | * " | + | |
- | * " | + | |
- | * **item** can be one of the following: | + | |
- | * core - limits the core file size (KB) | + | |
- | * **value** can be one of the following: | + | |
- | * core - limits the core file size (KB) | + | |
- | * data - max data size (KB) | + | |
- | * fsize - maximum filesize (KB) | + | |
- | * memlock - max locked-in-memory address space (KB) | + | |
- | * nofile - max number of open files | + | |
- | * rss - max resident set size (KB) | + | |
- | * stack - max stack size (KB) | + | |
- | * cpu - max CPU time (MIN) | + | |
- | * **nproc - max number of processes** | + | |
- | * as - address space limit | + | |
- | * maxlogins - max number of logins for this user | + | |
- | * maxsyslogins - max number of logins on the system | + | |
- | * priority - the priority to run user process with | + | |
- | * locks - max number of file locks the user can hold | + | |
- | * sigpending - max number of pending signals | + | |
- | * msgqueue - max memory used by POSIX message queues (bytes) | + | |
- | * nice - max nice priority allowed to raise to | + | |
- | * rtprio - max realtime priority | + | |
- | * chroot - change root to directory (Debian-specific) | + | |
- | + | ||
- | Login as the root and open configuration file: | + | |
< | < | ||
- | # vi / | + | Uso: fuser [-fMuv] [-a|-s] [-4|-6] [-c|-m|-n ESPACIO] [-k [-i] [-SIGNAL]] NOMBRE... |
- | </ | + | fuser -l |
+ | fuser -V | ||
+ | Muestra que procesos usan los archivos, zócalos o sistemas de archivos indicados. | ||
- | Following will prevent | + | -a, |
+ | -i, | ||
+ | -k, | ||
+ | -l, | ||
+ | -m, | ||
+ | -M, | ||
+ | -n, | ||
+ | -s, | ||
+ | -SIGNAL | ||
+ | -u, | ||
+ | -v, | ||
+ | -V, | ||
+ | -4, | ||
+ | -6, | ||
+ | - | ||
- | < | + | nombres udp/tcp: [local_port][, |
- | vivek hard nproc 300 | + | |
- | @student hard nproc 50 | + | |
- | @faculty soft nproc 100 | + | |
- | @pusers hard nproc 200 | + | |
</ | </ | ||
- | Above will prevent anyone in the student group from having more than 50 processes, faculty and pusers group limit is set to 100 and 200. Vivek can create only 300 process. Please note that KDE and Gnome desktop system can launch many process. | + | Ejemplo si queremos ver que proceso nos bloquea el pendrive y no nos deja desmontarlo |
- | + | ||
- | Save and close the file. Test your new system by dropping a form bomb: | + | |
< | < | ||
- | $ :(){ :|:& };: | + | $ fuser -m /dev/sdb1 |
+ | /dev/sdb1: 13542 | ||
</ | </ | ||
- | ==== Fuente ==== | + | Que proceso bloquea el archivo |
- | + | ||
- | http://www.cyberciti.biz/tips/linux-limiting-user-process.html | + | |
- | + | ||
- | + | ||
- | ===== Linux Audit ===== | + | |
- | + | ||
- | This is one of the key questions many new sys admin ask: | + | |
- | + | ||
- | How do I audit file events such as read / write etc? How can I use audit to see who changed a file in Linux? | + | |
- | + | ||
- | The answer is to use 2.6 kernels audit system. Modern Linux kernel (2.6.x) comes with auditd daemon. It's responsible for writing audit records to the disk. During startup, the rules in / | + | |
- | + | ||
- | In order to use audit facility you need to use following utilities=> | + | |
- | + | ||
- | => **ausearch** - a command that can query the audit daemon logs based for events based on different search criteria. | + | |
- | + | ||
- | => **aureport** - a tool that produces summary reports of the audit system logs. | + | |
- | + | ||
- | Note that following all instructions are tested on CentOS 4.x and Fedora Core and RHEL 4/5 Linux. | + | |
- | + | ||
- | ==== Task: install audit package ==== | + | |
- | + | ||
- | The audit package contains the user space utilities for storing and searching the audit records generate by the audit subsystem in the Linux 2.6 kernel. CentOS/Red Hat and Fedora core includes audit rpm package. Use yum or up2date command to install package | + | |
< | < | ||
- | # yum install audit | + | fuser / |
- | # up2date install audit | + | / |
</ | </ | ||
- | Auto start auditd service on boot | + | Si queremos ver que PID usa el puerto 80 tcp. |
< | < | ||
- | # ntsysv | + | fuser 80/tcp |
- | # chkconfig auditd on | + | 80/tcp: 17233 17652 17870 18252 18779 19234 19484 19547 19621 19679 32454 |
- | # /etc/init.d/auditd start | + | |
</ | </ | ||
- | ==== How do I set a watch on a file for auditing? ==== | + | Referencia útil como ver procesos escondidos: http:// |
- | + | ||
- | Let us say you would like to audit a /etc/passwd file. You need to type command as follows:''# | + | |
- | + | ||
- | Where, | + | |
- | + | ||
- | * **-w / | + | |
- | * **-p war** : Set permissions filter for a file system watch. It can be r for read, w for write, x for execute, a for append. | + | |
- | * **-k password-file** : Set a filter key on a /etc/passwd file (watch). The password-file is a filterkey (string of text that can be up to 31 bytes long). It can uniquely identify the audit records produced by the watch. You need to use password-file string or phrase while searching audit logs. | + | |
- | + | ||
- | In short you are monitoring (read as watching) a /etc/passwd file for anyone (including syscall) that may perform a write, append or read operation on a file. | + | |
- | + | ||
- | Wait for some time or as a normal user run command as follows:'' | + | |
- | + | ||
- | Following are more examples: | + | |
- | + | ||
- | ==== File System audit rules ==== | + | |
- | + | ||
- | Add a watch on "/ | + | |
- | < | + | |
- | # auditctl -w /etc/shadow -k shadow-file -p rwxa | + | |
- | </ | + | |
- | + | ||
- | === syscall audit rule === | + | |
- | + | ||
- | The next rule suppresses auditing for mount syscall exits''# | + | |
- | + | ||
- | === File system audit rule === | + | |
- | + | ||
- | Add a watch " | + | |
- | < | + | |
- | # auditctl -w /tmp -p e -k webserver-watch-tmp | + | |
- | </ | + | |
- | === syscall audit rule using pid === | + | |
- | + | ||
- | To see all syscalls made by a program called sshd (pid - 1005):''# | + | |
- | + | ||
- | ==== How do I find out who changed or accessed a file / | + | |
- | + | ||
- | Use ausearch command as follows: | + | |
- | + | ||
- | < | + | |
- | # ausearch -f / | + | |
- | # ausearch -f /etc/passwd | less | + | |
- | # ausearch -f /etc/passwd -i | less | + | |
- | </ | + | |
- | + | ||
- | Where | + | |
- | + | ||
- | * **-f / | + | |
- | * **-i** : Interpret numeric entities into text. For example, uid is converted to account name. | + | |
- | + | ||
- | Output: | + | |
- | + | ||
- | < | + | |
- | type=PATH msg=audit(03/ | + | |
- | type=CWD msg=audit(03/ | + | |
- | type=FS_INODE msg=audit(03/ | + | |
- | type=FS_WATCH msg=audit(03/ | + | |
- | type=SYSCALL msg=audit(03/ | + | |
- | </ | + | |
- | + | ||
- | Let us try to understand output | + | |
- | + | ||
- | * **audit(03/ | + | |
- | * **uid=lighttpd gid=lighttpd** : User ids in numerical format. By passing **-i** option to command you can convert most of numeric data to human readable format. In our example user is lighttpd used grep command to open a file | + | |
- | * **exe="/ | + | |
- | * perm_mask=read : File was open for read operation | + | |
- | + | ||
- | So from log files you can clearly see who read file using grep or made changes to a file using vi/vim text editor. Log provides tons of other information. You need to read man pages and documentation to understand raw log format. | + | |
- | + | ||
- | ==== Other useful examples ==== | + | |
- | + | ||
- | Search for events with date and time stamps. if the date is omitted, today is assumed. If the time is omitted, now is assumed. Use 24 hour clock time rather than AM or PM to specify time. An example date is 10/24/05. An example of time is 18:00:00. | + | |
- | + | ||
- | < | + | |
- | # ausearch -ts today -k password-file | + | |
- | # ausearch -ts 3/12/07 -k password-file | + | |
- | </ | + | |
- | + | ||
- | Search for an event matching the given executable name using -x option. For example find out who has accessed /etc/passwd using rm command: | + | |
- | + | ||
- | < | + | |
- | # ausearch -ts today -k password-file -x rm | + | |
- | # ausearch -ts 3/12/07 -k password-file -x rm | + | |
- | </ | + | |
- | + | ||
- | Search for an event with the given user name (UID). For example find out if user vivek (uid 506) try to open / | + | |
- | + | ||
- | < | + | |
- | # ausearch -ts today -k password-file -x rm -ui 506 | + | |
- | # ausearch -k password-file -ui 506 | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | Fuente | + | |
- | + | ||
- | Referencias útiles: | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[www.nsa.gov/ | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | [[http:// | + | |