Commit dcbba697 by Szeberényi Imre

buffer overflow példa

parents
#
# Makefile a buffover eloallitasahoz
#
PROG = buffover
SRCS = buffover.cpp secret.cpp
HDRS = secret.h
OBJS = $(SRCS:.cpp=.o)
CXXFLAGS = -ggdb -Wall -Werror
$(PROG): $(OBJS)
$(CXX) -o $(PROG) $(OBJS)
.PHONY:
clean:
rm -f $(OBJS) $(PROG)
# Egyszerusites: Minden .o fugg minden header-tol, es meg a Makefile-tol is
$(OBJS): $(HDRS) Makefile
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="buffover" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/buffover" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/buffover" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="buffover.cpp" />
<Unit filename="secret.cpp" />
<Unit filename="secret.h" />
<Extensions>
<DoxyBlocks>
<comment_style block="0" line="0" />
<doxyfile_project />
<doxyfile_build />
<doxyfile_warnings />
<doxyfile_output />
<doxyfile_dot />
<general />
</DoxyBlocks>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
/**
* \file: buffover.cpp
* (Latin-2 kodolasu fajl. Allitsa at a kodolast,
* ha a tovabbi kommentek nem olvashatok helyesen!)
*
* \brief Buffer overflow hiba bemutatsa
*
* A helyes jelsz: titok
* Prblja ki helyes s helytelen jelszval,
* majd 7-10 bet hosszsg tetszleges jelszval is!
*
*/
#include <iostream>
#include <cstring>
#include "secret.h"
using std::cin;
using std::cout;
using std::endl;
char buff[6];
bool pass = false;
int main(void) {
initOutputEncoding(); // belltjuk a kdkszletet a kimeneten
cout << "Ha tudja a jelszt, megnzheti a ZH krdst!\n";
cout << "Jelszo: ";
cin >> buff;
if (strcmp(buff, "titok") != 0) {
cout << "*** Hibas jelszo ***" << endl;
} else {
cout << "Helyes jelszo" << endl;
pass = true;
}
if (pass) {
cout << ">> Hozzaferhet a titokhoz: <<" << endl;
printSecret(); // kirja a titkos informcit
}
return 0;
}
/**
* \file: secret.cpp
* (Latin-2 kodolasu fajl. Allitsa at a kodolast,
* ha a tovabbi kommentek nem olvashatok helyesen!)
*
* \brief Pda az kezetes karakterek megjelentsre
*
* UTF-8 kezelse bonyolultabb, mert 1 karakter tbb byte hossz is lehet.
* LINUX-ban a LANG paranccsal be kell lltani a fjl kdolsnak
* megfelel nyelvet (pl: LANG=hu_HU, vagy LANG=hu_HU.utf8
*
* Ha tvoli termilemulcival csatlakozunk (pl. ssh, putty), akkor az
* kezethelyes megjelenshez annak a kdkszlett is jl kell belltani.
* (pl: putty -> change settings -> translation -> latin2)
*
* Kdkonverzi: iconv (van Windows s Linux vltozata is)
*/
#include <iostream>
#include <clocale>
#define WINX defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#if WINX
#include <windows.h>
#endif // WINX
#include "secret.h"
using std::cout;
using std::endl;
void printSecret() {
cout << "1. Mikor jelentkezik a buffer oveflow hiba?\n"
<< "\ta) reggel\n"
<< "\tb) aritmetikai tlcsordulskor\n"
<< "\tc) ha elfogy a memria\n"
<< "\td) egy vltozt (buffert) a program hosszabban r, mint annak a mrete" << std::endl;
}
void initOutputEncoding() {
setlocale(LC_ALL, "");
#if WINX
/// Windows alatt egyb varzslatra is szksg van ...
SetConsoleCP(1250);
SetConsoleOutputCP(1250);
#endif
}
#ifndef SECRET_H
#define SECRET_H
void printSecret();
void initOutputEncoding();
#endif // SECRET_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment