Programación y Desarrollo
Herramientas esenciales para programación, compilación y desarrollo de software en sistemas Linux.
Python
Section titled “Python”python / python3 - Intérprete Python
Section titled “python / python3 - Intérprete Python”Lenguaje de programación versátil y potente. Esencial para pentesting, automatización y desarrollo de herramientas de seguridad.
# Ejecutar script Pythonpython3 script.py
# Modo interactivopython3
# Ejecutar código directamentepython3 -c "print('Hello World')"
# Ejecutar módulopython3 -m module_name
# Verificar sintaxispython3 -m py_compile script.py
# Modo debugpython3 -m pdb script.py
# Instalar paquetespip3 install package_name
# Crear entorno virtualpython3 -m venv myenvsource myenv/bin/activateTip: Para pentesting, Python y Bash son los lenguajes más útiles. Python para scripts complejos y herramientas, Bash para automatización rápida y tareas del sistema.
ruby - Intérprete Ruby
Section titled “ruby - Intérprete Ruby”Lenguaje de programación elegante y expresivo. Popular para scripting y desarrollo web, usado en herramientas como Metasploit.
# Ejecutar script Rubyruby script.rb
# Modo interactivoirb
# Ejecutar código directamenteruby -e "puts 'Hello World'"
# Verificar sintaxisruby -c script.rb
# Instalar gemasgem install gem_name
# Listar gemas instaladasgem listperl - Intérprete Perl
Section titled “perl - Intérprete Perl”Lenguaje potente para procesamiento de texto y expresiones regulares. Excelente para manipulación de datos y scripts de una línea.
# Ejecutar script Perlperl script.pl
# Ejecutar código directamenteperl -e "print 'Hello World\n'"
# Modo one-liner para procesamiento de textoperl -pe 's/old/new/g' file.txt
# Verificar sintaxisperl -c script.pl
# Instalar móduloscpan Module::Namegcc - Compilador C/C++
Section titled “gcc - Compilador C/C++”Compilador estándar para C y C++. Fundamental para compilar exploits, herramientas de bajo nivel y código de rendimiento crítico.
# Compilar programa C básicogcc program.c -o program
# Compilar con warningsgcc -Wall program.c -o program
# Compilar con debuggcc -g program.c -o program
# Compilar con optimizacióngcc -O2 program.c -o program
# Compilar múltiples archivosgcc file1.c file2.c -o program
# Enlazar libreríasgcc program.c -lm -o program # math library
# Generar solo objetogcc -c program.c
# Mostrar información de compilacióngcc -v program.c -o programg++ - Compilador C++
Section titled “g++ - Compilador C++”Compilador específico para C++. Usado para proyectos orientados a objetos y aplicaciones complejas de sistemas.
# Compilar programa C++g++ program.cpp -o program
# Especificar estándar C++g++ -std=c++17 program.cpp -o program
# Compilar con warningsg++ -Wall -Wextra program.cpp -o programmake - Herramienta de construcción
Section titled “make - Herramienta de construcción”Automatiza el proceso de compilación usando Makefiles. Esencial para proyectos grandes y gestión de dependencias.
# Compilar usando Makefilemake
# Compilar target específicomake target_name
# Limpiar archivos compiladosmake clean
# Compilar con múltiples jobsmake -j4
# Mostrar comandos sin ejecutarmake -n
# Forzar recompilaciónmake -Bjavac - Compilador Java
Section titled “javac - Compilador Java”# Compilar archivo Javajavac Program.java
# Compilar con classpathjavac -cp /path/to/libs Program.java
# Compilar múltiples archivosjavac *.java
# Generar información de debugjavac -g Program.javajava - Máquina Virtual Java
Section titled “java - Máquina Virtual Java”# Ejecutar programa Javajava Program
# Ejecutar con classpathjava -cp /path/to/classes Program
# Ejecutar JARjava -jar program.jar
# Configurar memoriajava -Xmx1024m -Xms512m Program
# Modo debugjava -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 Programjavadoc - Generador de documentación
Section titled “javadoc - Generador de documentación”# Generar documentaciónjavadoc *.java
# Generar en directorio específicojavadoc -d docs *.javaHerramientas de Desarrollo
Section titled “Herramientas de Desarrollo”gdb - Debugger GNU
Section titled “gdb - Debugger GNU”Depurador potente para análisis de binarios y reverse engineering. Crucial para análisis de malware y desarrollo de exploits.
# Iniciar debuggergdb program
# Comandos dentro de gdb:# run - ejecutar programa# break main - establecer breakpoint# step - ejecutar línea por línea# continue - continuar ejecución# print variable - mostrar valor de variable# backtrace - mostrar stack trace# quit - salir
# Debug con core dumpgdb program core
# Attach a proceso en ejecucióngdb -p PIDstrace - Rastrear system calls
Section titled “strace - Rastrear system calls”# Rastrear system callsstrace program
# Rastrear proceso existentestrace -p PID
# Filtrar system calls específicosstrace -e trace=open,read,write program
# Guardar output en archivostrace -o trace.log program
# Mostrar timestampsstrace -t programltrace - Rastrear library calls
Section titled “ltrace - Rastrear library calls”# Rastrear llamadas a libreríasltrace program
# Rastrear proceso existenteltrace -p PID
# Filtrar funciones específicasltrace -e malloc,free programEditores y IDEs
Section titled “Editores y IDEs”vim / vi - Editor de texto
Section titled “vim / vi - Editor de texto”# Abrir archivovim filename
# Comandos básicos en vim:# i - modo inserción# :w - guardar# :q - salir# :wq - guardar y salir# :q! - salir sin guardar# /pattern - buscar# :%s/old/new/g - reemplazarnano - Editor simple
Section titled “nano - Editor simple”# Abrir archivonano filename
# Atajos en nano:# Ctrl+O - guardar# Ctrl+X - salir# Ctrl+W - buscar# Ctrl+K - cortar línea# Ctrl+U - pegaremacs - Editor avanzado
Section titled “emacs - Editor avanzado”# Abrir archivoemacs filename
# Atajos básicos:# Ctrl+X Ctrl+S - guardar# Ctrl+X Ctrl+C - salir# Ctrl+S - buscarEjemplos para Pentesting
Section titled “Ejemplos para Pentesting”Compilar exploits
Section titled “Compilar exploits”# Compilar exploit en Cgcc -o exploit exploit.c
# Compilar con flags específicos para bypassgcc -fno-stack-protector -z execstack exploit.c -o exploit
# Compilar exploit multiplataformagcc -m32 exploit.c -o exploit32 # 32-bitgcc -m64 exploit.c -o exploit64 # 64-bitDesarrollo de herramientas personalizadas
Section titled “Desarrollo de herramientas personalizadas”# Script Python para reconocimientocat > port_scanner.py << 'EOF'#!/usr/bin/env python3import socketimport sys
def scan_port(host, port): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) result = sock.connect_ex((host, port)) sock.close() return result == 0 except: return False
host = sys.argv[1]for port in range(1, 1001): if scan_port(host, port): print(f"Port {port} is open")EOF
chmod +x port_scanner.pyAnálisis de binarios
Section titled “Análisis de binarios”# Información de archivo ejecutablefile binaryreadelf -h binaryobjdump -d binary
# Strings en binariosstrings binary | grep -i password
# Dependencias de libreríasldd binary
# Símbolos en binarionm binaryDebugging de exploits
Section titled “Debugging de exploits”# Debug con gdbgdb ./vulnerable_program(gdb) run $(python -c "print 'A'*100")(gdb) info registers(gdb) x/20x $esp
# Análisis con stracestrace -e trace=file ./program 2>&1 | grep -E "(open|access)"Automatización y Scripts
Section titled “Automatización y Scripts”Scripts de compilación
Section titled “Scripts de compilación”#!/bin/bashTOOLS_DIR="/opt/tools"SRC_DIR="/tmp/src"
# Compilar nmap desde fuentecd $SRC_DIRwget https://nmap.org/dist/nmap-7.94.tar.bz2tar -xjf nmap-7.94.tar.bz2cd nmap-7.94./configure --prefix=$TOOLS_DIRmake && make installMakefile para proyectos de pentesting
Section titled “Makefile para proyectos de pentesting”CC=gccCFLAGS=-Wall -gTARGETS=exploit1 exploit2 scanner
all: $(TARGETS)
exploit1: exploit1.c $(CC) $(CFLAGS) -o $@ $<
exploit2: exploit2.c $(CC) $(CFLAGS) -fno-stack-protector -z execstack -o $@ $<
scanner: scanner.c $(CC) $(CFLAGS) -o $@ $<
clean: rm -f $(TARGETS)
install: all cp $(TARGETS) /opt/tools/
.PHONY: all clean installConsideraciones de Seguridad
Section titled “Consideraciones de Seguridad”Compilación segura
Section titled “Compilación segura”# Habilitar protecciones de seguridadgcc -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now program.c
# Verificar protecciones en binariochecksec --file=programAnálisis estático de código
Section titled “Análisis estático de código”# Usar herramientas de análisiscppcheck source.csplint source.c
# Buscar vulnerabilidades comunesgrep -r "strcpy\|strcat\|sprintf\|gets" source_code/Nota de Seguridad: Al compilar exploits o herramientas de pentesting, asegúrate de hacerlo en un entorno controlado. Algunos exploits pueden ser detectados por antivirus o sistemas de prevención de intrusiones.