#include <malloc.h>
#include <stdio.h>
int longitud(FILE *archivo);
int main(int argc, char *argv[]){
if(argc < 2){
puts("Necesita un parametro");
return 1;}
int longi, i;char *shellcode;
FILE *archivo=fopen(argv[1], "rb");
longi=longitud(archivo);
shellcode=(char *)malloc(longi);
for(i=0;i<longi;i++){shellcode[i]=getc(archivo);}
fclose(archivo);
((void(*)())shellcode)();
free(shellcode);
return 0;}
int longitud(FILE *archivo){
int longi;
fseek(archivo, 0, SEEK_END);
longi=ftell(archivo);
fseek(archivo, 0, SEEK_SET);
return longi;}
martes, 14 de noviembre de 2023
[C] Probar Shellcodes
[C] Extraer shellcodes desde fichero
#include <stdio.h>
int longitud(FILE *archivo);
int main(int argc, char *argv[]){
int longi,i;
if(argc < 2){
puts("Necesita un parametro");
return 1;}
FILE *archivo=fopen(argv[1], "rb");
longi=longitud(archivo);
printf("char shellcode[]=\"");
for(i=0;i<longi;i++){
printf("\\x%x", getc(archivo));}
printf("\";\n");
fclose(archivo);
return 0;}
int longitud(FILE *archivo){
int longi;
fseek(archivo, 0, SEEK_END);
longi=ftell(archivo);
fseek(archivo, 0, SEEK_SET);return longi;}
lunes, 13 de noviembre de 2023
[C] Convertir texto a hexadecimal
/*** Hex Converter* Coded By Doddy H* Based in hex encoder by Ka0x*/
#include <stdio.h>
#include <string.h>
void head(){printf("\n -- == Hex Converter == --\n\n"); }
void end() {printf("\n\n\n -- == Coded By Doddy H == --\n");}
int main ( int argc, char **argv ){
char *text;
int i,total;
head();
if(argc != 2) {
printf("\n[+] Sintax : hex <text>");
} else {
text = argv[1];
total = strlen(text);
printf("\n[Text] : %s\n",text);
printf("[Encode] : 0x");
for(i=0;i<total;i++){
printf("%x",text[i]);
}
}
end();
return 0;
}
/** The End ? */
[CPP] Encontrar cadena dentro de texto
#include <windows.h>#include <iostream>#include <fstream>
using namespace std;
int Text(char *palabra,char color){
switch(color){
case 'V':
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN);cout<<palabra<<endl; break;
case 'R':SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_RED);cout<<palabra<<endl;break;
default: cout<<"El valor ingresado no es valido"<<endl;}}
//##################FindString#########################
int FindString(char *archivo,char *palabra){
char dat[1000];
ifstream arch; arch.open(archivo);if(!arch){
cout<<"ERROR AL ABRIR EL ARCHIVO"<<endl;}
else{
while(!arch.eof() && arch.getline(dat,1000)){
if(strstr(dat,palabra)==NULL){Text(dat,'R');
}else{Text(dat,'V');}}}}
int main(){
FindString("c:\\archivo.cpp","long");
cin.get();
return 0;
}
[C] Cifrado Cesar
#include <stdio.h>
#include <string.h>
// cadenas referenciadoras para el mensaje original y cifrado
char *alfabeto="abcdefghijklmnñopqrstuvwxyz";
char *cifrado ="DEFGHIJKLMNÑOPQRSTUVWXYZABC";
//Prototipo de funciones para cifrar y decibrar el texto
char* cifra(char*);
char* descifra(char*);
//Funcion principal para probar el uso de las funciones
int main(void)
{
char cadena[300];
char *res;
fprintf(stdout,"Ingrese texto a cifrar\t:\n");
fscanf(stdin,"%s",cadena);
res=cifra(cadena);
fprintf(stdout,"\nLa cadena Cifrada es\t:%s\n\n",res);
res=descifra(res);
fprintf(stdout,"La cadena Desifrada es\t:%s",res);
getchar();
getchar();
return 0;
}
//Funcion que cifra el mensaje
char* cifra(char *text)
{
int i,j;
for(j=0;j<strlen(text);j++)
{
for(i=0;i<strlen(alfabeto);i++)
{
if(*(text+j)==*(alfabeto+i))
{
*(text+j)=*(cifrado+i);
}
}
}
return text;
}
//Funcion que descifra el mensaje
char* descifra(char *text)
{
int i,j;
for(j=0;j<strlen(text);j++)
{
for(i=0;i<strlen(alfabeto);i++)
{
if((*(text+j))==*(cifrado+i))
{
*(text+j)=*(alfabeto+i);
}
}
}
return text;
}
[C] Cifrado Garbo
/**********************************************
* Nombre : garbo.c
* Author : S[e]C
* Date : 30-06-09
* Description : Code/Decode Cifrado Garbo
***********************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* * Alfabeto original y los 5 alfabetos de cifrado*/
char alfabeto[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char alf1[] ="GHIJKLMNOPQRSTUVWXYZABCDEFghijklmnopqrstuvwxyzabcdef";
char alf2[] ="EFGHIJKLMABCDNOPQRSTZUVWXYefghijklmabcdnopqrstzuvwxy";
char alf3[] ="AZYBXCWDVEFUTGHSRIJQKPLMONazybxcwdvefutghsrijqkplmon";
char alf4[] ="QRSTUVWXYZBACEDFHGJILKMONPqrstuvwxyzbacedfhgjilkmonp";
char alf5[] ="DEGFIHJABCKOLMNPRQTSVUZXYWdegfihjabckolmnprqtsvuzxyw";
//Prototipo funciones cifrado y descifrado
void cifra(char *text);
void descifra(char *text);
int main(void){
char cad[50];
fprintf(stdout,"Cadena a cifrar\t:");
fscanf(stdin,"%s",cad);
cifra(cad); //primera pasada
cifra(cad); //segunda pasada
printf("Cadena codificada\t:%s\n",cad);
descifra(cad); //revierte primera pasada
descifra(cad); //revierte segunda pasada
printf("\nCadena decodificada\t:%s\n",cad);
getchar();
getchar();
return 0;
}
void cifra(char *text){
int i,k,modulo;
for(i=0;*(text+i)!='\0';i++){
modulo=(i+1)%5; /* Obtengo el modulo de la posicion+1 ya que se considera desde
la letra Nº 1 de la cadena, no la posicion numero 0 de ella. */
switch(modulo){
case 0: //si el modulo es 0 uso el alfabeto 5
for(k=0;*(alfabeto+k)!='\0';k++){ /*Miro cada letra del alfabeto*/
if(*(text+i)==*(alfabeto+k)) //y comparo con la primera letra de la cadena
{ //si son iguales:
*(text+i)=*(alf5+k); //le asigno el valor del alfabeto de cifrado correspondiente(alfX)
break; //salgo del ciclo.
}
}
break;
case 1: //si el modulo es 1 uso el alfabeto 1
for(k=0;*(alfabeto+k)!='\0';k++)
{
if(*(text+i)==*(alfabeto+k))
{
*(text+i)=*(alf1+k);
break;
}
}
break;
case 2: // si el modulo es 2 uso el alfabeto 2
for(k=0;*(alfabeto+k)!='\0';k++)
{
if(*(text+i)==*(alfabeto+k))
{
*(text+i)=*(alf2+k);
break;
}
}
break;
case 3: // si el modulo es 3 uso el alfabeto 3
for(k=0;*(alfabeto+k)!='\0';k++)
{
if(*(text+i)==*(alfabeto+k))
{
*(text+i)=*(alf3+k);
break;
}
}
break;
case 4: // si el modulo es 4 uso el alfabeto 4
for(k=0;*(alfabeto+k)!='\0';k++)
{
if(*(text+i)==*(alfabeto+k))
{
*(text+i)=*(alf4+k);
break;
}
}
break;
default: // si el modulo es 4 uso el alfabeto 4
for(k=0;*(alfabeto+k)!='\0';k++)
{
if(*(text+i)==*(alfabeto+k))
{
*(text+i)=*(alf5+k);
break;
}
}
}
}
}
void descifra(char *text)
{
int i,k,modulo;
for(i=0;*(text+i)!='\0';i++)
{
modulo=(i+1)%5; //Obtengo el modulo, IDEM que en el proceso de cifrado
switch(modulo)
{
case 0: //si el modulo es 0 decodifico la letra buscando en el alfabeto 5
for(k=0;*(alf5+k)!='\0';k++) //miro cada letra del alfabeto X
{ //( X = alfabeto correspondiente al modulo )
if(*(text+i)==*(alf5+k)) //comparo con la primera letra de la cadena
{ //si son iguales:
*(text+i)=*(alfabeto+k); //Le asigno la letra correspondiente
break; //en el alfabeto Original, y salgo del ciclo.
}
}
break;
case 1: //si el modulo es 0 decodifico la letra buscando en el alfabeto 1
for(k=0;*(alf1+k)!='\0';k++)
{
if(*(text+i)==*(alf1+k))
{
*(text+i)=*(alfabeto+k);
break;
}
}
break;
case 2: //si el modulo es 0 decodifico la letra buscando en el alfabeto 2
for(k=0;*(alf2+k)!='\0';k++)
{
if(*(text+i)==*(alf2+k))
{
*(text+i)=*(alfabeto+k);
break;
}
}
break;
case 3: //si el modulo es 0 decodifico la letra buscando en el alfabeto 3
for(k=0;*(alf3+k)!='\0';k++)
{
if(*(text+i)==*(alf3+k))
{
*(text+i)=*(alfabeto+k);
break;
}
}
break;
case 4: //si el modulo es 0 decodifico la letra buscando en el alfabeto 4
for(k=0;*(alf4+k)!='\0';k++)
{
if(*(text+i)==*(alf4+k))
{
*(text+i)=*(alfabeto+k);
break;
}
}
}
}
}
[C] Crackeador mysql
/** Esto es un rapido crakeador de fuerza bruta para hashed MySQL*Se puede romper una contraseña de 8 caracteres que contiene todos *los caracteres ASCII en cuestión de horas en un PC normal.*Este programa es de dominio público. Compartir y disfrutar.*
* Ejemplo:
* $ gcc -O2 -fomit-frame-pointer mysqlfast.c -o mysqlfast
* $ mysqlfast 6294b50f67eda209
* Hash: 6294b50f67eda209
* Trying length 3
* Trying length 4
* Found pass: barf
*
* La contraseña de MySQL función hash se podría fortalecer considerablemente
*/
//Necesitas libssl y libpthread
#include <stdio.h>
typedef unsigned long u32;
/* Caracteres permitidos en la contraseña; 33-126 es imprimible ASCII */
#define MIN_CHAR 33
#define MAX_CHAR 126
/* La longitud máxima de la contraseña */
#define MAX_LEN 12
#define MASK 0x7fffffffL
int crack0(int stop, u32 targ1, u32 targ2, int *pass_ary){
int i, c;
u32 d, e, sum, step, diff, div, xor1, xor2, state1, state2;
u32 newstate1, newstate2, newstate3;
u32 state1_ary[MAX_LEN-2], state2_ary[MAX_LEN-2];
u32 xor_ary[MAX_LEN-3], step_ary[MAX_LEN-3];
i = -1;
sum = 7;
state1_ary[0] = 1345345333L;
state2_ary[0] = 0x12345671L;
while (1) {
while (i < stop) {
i++;
pass_ary = MIN_CHAR;
step_ary = (state1_ary & 0x3f) + sum;
xor_ary = step_ary*MIN_CHAR + (state1_ary << 8);
sum += MIN_CHAR;
state1_ary[i+1] = state1_ary ^ xor_ary;
state2_ary[i+1] = state2_ary
+ ((state2_ary << 8) ^ state1_ary[i+1]);
}
state1 = state1_ary[i+1];
state2 = state2_ary[i+1];
step = (state1 & 0x3f) + sum;
xor1 = step*MIN_CHAR + (state1 << 8);
xor2 = (state2 << 8) ^ state1;
for (c = MIN_CHAR; c <= MAX_CHAR; c++, xor1 += step) {
newstate2 = state2 + (xor1 ^ xor2);
newstate1 = state1 ^ xor1;
newstate3 = (targ2 - newstate2) ^ (newstate2 << 8);
div = (newstate1 & 0x3f) + sum + c;
diff = ((newstate3 ^ newstate1) - (newstate1 << 8)) & MASK;
if (diff % div != 0) continue;
d = diff / div;
if (d < MIN_CHAR || d > MAX_CHAR) continue;
div = (newstate3 & 0x3f) + sum + c + d;
diff = ((targ1 ^ newstate3) - (newstate3 << 8)) & MASK;
if (diff % div != 0) continue;
e = diff / div;
if (e < MIN_CHAR || e > MAX_CHAR) continue;
pass_ary[i+1] = c;
pass_ary[i+2] = d;
pass_ary[i+3] = e;
return 1;
}
while (i >= 0 && pass_ary >= MAX_CHAR) {
sum -= MAX_CHAR;
i--;
}
if (i < 0) break;
pass_ary++;
xor_ary += step_ary;
sum++;
state1_ary[i+1] = state1_ary ^ xor_ary;
state2_ary[i+1] = state2_ary
+ ((state2_ary << 8) ^ state1_ary[i+1]);
}
return 0;
}
void crack(char *hash){
int i, len;
u32 targ1, targ2, targ3;
int pass[MAX_LEN];
if ( sscanf(hash, "%8lx%lx", &targ1, &targ2) != 2 ) {
printf("Invalid password hash: %s\n", hash);
return;
}
printf("Hash: %08lx%08lx\n", targ1, targ2);
targ3 = targ2 - targ1;
targ3 = targ2 - ((targ3 << 8) ^ targ1);
targ3 = targ2 - ((targ3 << 8) ^ targ1);
targ3 = targ2 - ((targ3 << 8) ^ targ1);
for (len = 3; len <= MAX_LEN; len++) {
printf("Trying length %d\n", len);
if ( crack0(len-4, targ1, targ3, pass) ) {
printf("Found pass: ");
for (i = 0; i < len; i++)
putchar(pass);
putchar('\n');
break;
}
}
if (len > MAX_LEN)
printf("Pass not found\n");
}
int main(int argc, char *argv[]){
int i;
if (argc <= 1) printf("usage: %s hash\n", argv[0]);
for (i = 1; i < argc; i++) crack(argv);
return 0;
}