Słownik BruteForce

0

Witam,
Potrzebuję krótki skrypt który wygeneruje mi słowniczek dla ataku BruteForce.
Dodam, że jest to potrzebne mi dla testów na domowej sieci ze ustalonym z góry hasłem.

Hasło ma się składać ze słowa "tajemnica".
Może zawierać małe i duże litery oraz obie litery "a" może być zastąpiona cyfrą 4, litera "i" cyfrą 1 ale nie muszą.
Potrzebuję skryptu który wygeneruje mi wszystkie możliwe kombinacje dla tego słownika ale nie mogę sam sobie z nim poradzić :/

Czy ktoś może mi pomóc?

0

słownik i bruteforce? Słownik to możesz sam sobie zrobić nie jest tego aż tak dużo.

0

Aktualnie mam coś takiego :v
Nie wiem co dalej mogę z tym zrobić

2

Panie Żurawiecki, nikt nie będzie ściągał spakowanego pliku. Wrzuć to normalnie używając markdowna albo skorzystaj z pastebin i wklej link.

0

https://pastebin.com/NynE0pHG

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

string wyraz;
char i[9]

int main ()
{
    char i1[2]=('t','T');
    char i2[3]=('a','A','4');
    char i3[2]=('j','J');
    char i4[2]=('e','E');
    char i5[2]=('m','M');
    char i6[2]=('n','N');
    char i7[3]=('i','I','1');
    char i8[2]=('c','C');
    char i9[3]=('a','A','4');

        for(int i1=0; i1<=2; i1++)
        {
            for(int i2=1; i2<=3; i2++)
                for(int i3=1; i3<=2; i3++)
                    for(int i4=1; i4<=2; i4++)
                        for(int i5=1; i5<=2; i5++)
                            for(int i6=1; i6<=2; i6++)
                                for(int i7=1; i7<=3; i7++)
                                    for(int i8=1; i8<=2; i8++)
                                        for(int i9=1; i9<=3; i9++);

            wyraz=i1+i2+i3+i4+i5+i6+i7+i8+i9;
        }

    cout<<wyraz<<endl;
    return 0;
}
0

Mam nowy kod który niestety używa tylko dwóch znaków dla każdego pola w kombinacji.
Czy mógłby ktoś powiedzieć jak go przerobić żeby dało się wpisać 3 znaki w jedno pole?

https://pastebin.com/5sghU0Pc

0

Takie coś Ci napisałem, nie jest to zbytnio szybkie, lecz zasada działania chyba została zachowana.
Dla Ciebie interesująca jest metoda brute::print_combinations.

#include <iostream>
#include <string>
#include <algorithm>
#include <regex>
#include <cctype>
#include <map>
#include <vector>

class counter{
	int num_vals;
	unsigned int max_number;
	std::vector<unsigned int> count;
	bool ended;
public:
	counter(unsigned int max, int num_values) : num_vals(num_values),max_number(max),ended(false){
		for(int i =0;i<num_values;++i)
			count.push_back(0);
	}
	~counter() = default;
	bool end(){return ended;}
	counter operator++(int){
		for(int i=num_vals-1;i >= 0;--i){
			if(count[i]+1>max_number){
				count[i] = 0;
			}else{
				count[i]++;
				return *this;
			}
		}
		ended = true;
		return *this;
	}
	int operator[](int num){
		return static_cast<unsigned int>(num) < count.size() ? count[num] : 0 ;
	}
};

class brute{
	static const std::string boolean_value[2];

	std::regex regex;
	std::smatch match;

	std::map<char,char> letters;
	bool upcase;
	unsigned int length;
public:
	brute() : upcase(false),length(0){} 
	~brute() = default;

	bool up(){return upcase;}
	unsigned int len(){return length;}
	std::map<char,char> &get_map(){return letters;}

	void set_upcase(std::string up);
	void set_length(std::string l);
	void insert_letters(std::string ls);
	void insert_change(std::string ch);
	void print_combinations();
};

const std::string brute::boolean_value[] = {"true","false"};

void brute::set_upcase(std::string up){
	regex = "(\\S+)";
	std::regex_match(up,match,regex);
	if(match.size() > 0){
		std::string str = match[1];
		std::transform(str.begin(), str.end(), str.begin(), ::tolower);
		upcase = str == "true" ? true : false;
	}	
}

void brute::set_length(std::string l){
	int value = std::stoi(l);
	if(value <= 0)return;
	length = static_cast<unsigned int>(value);
}

void brute::insert_letters(std::string ls){
	for(std::string::iterator iter = ls.begin();iter != ls.end();++iter){
		letters[*iter] = 0;
	}
}

void brute::insert_change(std::string ch){
	regex = "(\\S{1}):(\\S{1}),?";
	std::string str = ch;
	while(std::regex_search(str,match,regex)){
		letters[std::string(match[1]).at(0)] = std::string(match[2]).at(0);
		str = match.suffix().str();
	}	
}

void brute::print_combinations(){
	std::vector<char> result(length+1,'\0');
	std::vector<char> result_change(length+1,'\0');	

	std::vector<char> letter;
	for(auto m : letters){letter.push_back(m.first);}
        if(upcase)for(auto m : letters){letter.push_back(toupper(m.first));}
	
	bool change = false;
	for(counter ct(letter.size()-1,length);!ct.end();ct++){
		for(unsigned int i =0;i<length;++i){
			result_change[i] = result[i] = letter[ct[i]];
			if(letters[letter[ct[i]]] != 0){
				result_change[i] = letters[letter[ct[i]]];
				change = true;
			}
		}
		if(change){
			std::cout << result_change.data() << std::endl;
			change = false;
		}
		std::cout << result.data() << std::endl;
	}
}


int main(int argc,char **argv){
	brute obj;
	if(argc > 1)obj.insert_letters(std::string(argv[1]));
	if(argc > 2)obj.set_upcase(std::string(argv[2]));
	if(argc > 3)obj.set_length(std::string(argv[3]));
	if(argc > 4)obj.insert_change(std::string(argv[4]));

	const std::string mode = "-s";
	bool silent = false;
	for(int i=0;i < argc;++i){
		if(mode == argv[i]){
			silent = true;
			break;
		}
	}

	if(!silent){
		std::cout << "Possible arguments <letters> <upcase_true> <length> <letter:change,...> " << std::endl;
	    std::cout << "Silent mode: -s (as last argument)\n";
    	std::cout << "Example: program abcdef true 3 a:4,b:6 " << std::endl;

		std::string uped = obj.up() ? "true" : "false";
		std::cout 	<< "\nBrute\n\nupcase?:\t" << uped << std::endl
					<< "Length :\t" << obj.len() << std::endl
					<< "Letters:\n";

		for(auto m : obj.get_map()){
			std::cout << m.first << ":\t" << m.second << std::endl;
		}

		std::cout << "\n-----\nOut:\n-----\n";
	}

	obj.print_combinations();
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1