-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploitable2.cpp
More file actions
39 lines (31 loc) · 1.1 KB
/
Copy pathexploitable2.cpp
File metadata and controls
39 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// **************************************************************
// Fuzzing example - buffer overflow in a simple file read mockup
//
// Copyright 2020
// Charley Lucas
// charley@zerosquared.io
// **************************************************************
#include <stdlib.h>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;
#define BUFFER_SIZE 20
int main(int argc, char* argv[]) {
ifstream inputfile;
string line;
int i = 0;
char filename[BUFFER_SIZE]; // Allocate space for BUFFER_SIZE characters plus the null
char username[BUFFER_SIZE]; // Allocate space for BUFFER_SIZE characters plus the null
if (argc < 2) {
cout << "Enter input filename on the command line.\n";
exit(0);
}
cout << "Reading file " << argv[1] << endl << endl;
inputfile.open(argv[1]); // Not going to bother cleaning the input filename
while (getline (inputfile, line)) {
strcpy(username, line.c_str()); // Unprotected copy - may overwrite our allocated memory
cout << i++ << ": " << username << endl;
}
}