Skip to content

Commit

Permalink
Created the trash generator functions their own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxagast committed Oct 5, 2016
1 parent 1f072cc commit 5b40a5a
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 180 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
bin_PROGRAMS = ansvif find_suid faulty
noinst_LIBRARIES = libgzstream.a
libgzstream_a_SOURCES = include/gzstream/gzstream.h include/gzstream/gzstream.C
ansvif_SOURCES = src/common.cpp src/linux/bin2hex.cpp src/linux/bin2hex_pc.cpp src/linux/popen2.cpp src/linux/main.cpp src/linux/help.cpp src/match_seg.cpp src/linux/sys_string.cpp src/linux/sys_string_pc.cpp src/linux/man_read.cpp include/gzstream/gzstream.h include/xmlwriter/xml_writer.hpp
ansvif_SOURCES = src/common.cpp src/linux/bin2hex.cpp src/linux/bin2hex_pc.cpp src/linux/popen2.cpp src/linux/main.cpp src/linux/help.cpp src/match_seg.cpp src/linux/sys_string.cpp src/linux/sys_string_pc.cpp src/linux/man_read.cpp src/trash.cpp include/gzstream/gzstream.h include/xmlwriter/xml_writer.hpp
ansvif_LDADD = -lgzstream -lstdc++ -lpthread -lz -L.
ansvif_CPPFLAGS = -O3
ansvif_LDFLAGS = -I./include/gzstream -I./include/xml_writer
Expand Down
183 changes: 4 additions & 179 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#define WRITE 1




std::string make_garbage(int trash, int buf, std::string opt_other_str,
bool is_other, bool never_rand);
std::string trash_generator(int trash, int buf, std::string user_junk,
std::string opt_other_str, bool never_rand);
bool match_seg(int buf_size, std::vector<std::string> opts,
std::vector<std::string> spec_env, std::string path_str,
std::string strip_shell, bool rand_all, bool write_to_file,
Expand Down Expand Up @@ -90,22 +92,6 @@ int rand_me_plz(int rand_from, int rand_to) {
return (roll);
}

char fortune_cookie() {
/* because fortune cookies taste good */
char chr;
/* all the characters that make up hex */
const char *hex_digits = "0123456789ABCDEF";
int i;
for (i = 0; i < 1; i++) {
/* now we just get two random hex characters and
* return them to the routine
*/
chr = hex_digits[(rand_me_plz(0, 255))];
}
return (chr);
}


int reaper(int grim, int t_timeout) {
/* run the timer and after the timeout we'll run
* SIGKILL on it (kill -9 equivilant on linux)
Expand Down Expand Up @@ -165,167 +151,6 @@ std::vector<std::string> get_other(std::string filename,
return (other_vec);
}

std::string trash_generator(int trash, int buf, std::string user_junk,
std::string opt_other_str, bool never_rand) {
/* this is the trash generator, here we generate
* bad input, some of it random, some of it precrafted
* and some of it user supplied to try to crash the
* program at hand
*/
std::string junk = "";
std::string hex_stuff;
int trash_num;
if (trash == 0) {
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = "A" + junk;
}
}
if (trash == 1) {
junk = "-1";
}
if (trash == 2) {
junk = "1";
}
if (trash == 3) {
junk = "0";
}
if (trash == 4) {
junk = "2";
}
if (trash == 5) {
int hex_null_i = 0x00;
std::stringstream hex_null_ss;
hex_null_ss << hex_null_i;
junk = hex_null_ss.str();
}
if (trash == 6) {
for (trash_num = 0; trash_num < buf / 2; trash_num++) {
junk = "\%s" + junk;
}
}
if (trash == 7) {
for (trash_num = 0; trash_num < buf / 2; trash_num++) {
junk = "\%n" + junk;
}
}
if (never_rand == false) {
if (trash == 8) {
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = junk += fortune_cookie();
}
}
}
if (trash == 9) { // front
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = "A" + junk;
}
junk = user_junk + junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(0, buf);
else
return ("OOR");
}
if (trash == 10) {
for (trash_num = 0; trash_num < buf / 2; trash_num++) {
junk = "\%s" + junk;
}
junk = user_junk + junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(0, buf);
else
return ("OOR");
}
if (never_rand == false) {
if (trash == 11) {
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = junk += fortune_cookie();
}
junk = user_junk + junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(0, buf);
else
return ("OOR");
}
}
if (trash == 12) {
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = "A" + junk;
}
junk = junk + user_junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(junk.length() - buf);
else
return ("OOR");
}
if (trash == 13) {
for (trash_num = 0; trash_num < buf / 2; trash_num++) {
junk = "\%s" + junk;
}
junk = junk + user_junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(junk.length() - buf);
else
return ("OOR");
}
if (never_rand == false) {
if (trash == 14) {
for (trash_num = 0; trash_num < buf; trash_num++) {
junk = junk += fortune_cookie();
}
junk = junk + user_junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(junk.length() - buf);
else
return ("OOR");
}
}
if (trash == 15) {
for (trash_num = 0; trash_num < buf / 2; trash_num++) {
junk = "\%n" + junk;
}
junk = junk + user_junk;
if (buf - user_junk.length() < junk.size())
junk = junk.substr(junk.length() - buf);
else
return ("OOR");
}
if (trash == 16) {
junk = opt_other_str;
}
/* return the junk to put in between the args */
return (junk);
}

std::string make_garbage(int trash, int buf, std::string opt_other_str,
bool is_other, bool never_rand) {
buf = buf - 1;
std::string all_junk;
if (is_other == true) {
if (isatty(STDIN_FILENO)) {
/* if it's a stdin then we'll call the tash generator */
std::string user_stuff = "";
all_junk = trash_generator(trash, buf, user_stuff, opt_other_str,
never_rand);
} else {
std::string user_stuff;
getline(std::cin, user_stuff);
all_junk =
trash_generator(trash, buf, user_stuff, opt_other_str, never_rand);
}
} else if (is_other == false) {
if (isatty(STDIN_FILENO)) {
std::string user_stuff = "";
all_junk = trash_generator(trash, buf, user_stuff, "", never_rand);
} else {
std::string user_stuff;
getline(std::cin, user_stuff);
all_junk = trash_generator(trash, buf, user_stuff, "", never_rand);
}
}
/* return all the junk the trash generator made */
return (all_junk);
}

void write_seg(std::string filename, std::string line) {
/* this is just a simple file writing routine
* used mostly for logging and writing the junk
Expand Down
Loading

0 comments on commit 5b40a5a

Please sign in to comment.