Skip to content

Commit 7d3e4f1

Browse files
committed
bug fix
1 parent eff7f36 commit 7d3e4f1

13 files changed

+1031
-222
lines changed

skf/logs/2015-03.txt

Lines changed: 881 additions & 0 deletions
Large diffs are not rendered by default.

skf/markdown/code_examples/php/1-code_example--File_upload--.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,40 @@ File upload
6969
die();
7070
}
7171
72-
//Check for uploading out of intended directory
72+
73+
//here we create a function which checks te allowed patterns
74+
function checkpattern(){
75+
76+
//Check for uploading out of intended directory
7377
$array = array("/%2e%2e%2f/" ,"/..//" ,"/%2e/" ,"/%5c/" ,"/%252e/" ,"/%c0%af/" ,"%/c1%9c/");
74-
75-
foreach($array as $injectPattern){
76-
while(preg_match($injectPattern , $this->_image['name'])){
78+
79+
foreach($array as $Pattern){
80+
while(preg_match($Pattern , $this->_image['name'])){
81+
//If the value is valid we send a log to the logging file.
82+
setLog($_SESSION['userID'],"Validation was succesfull for filename", "SUCCESS", date(dd-mm-yyyy), $privelige, "NULL");
7783
78-
//Set a log for whenever there is unexpected userinput with a threat level
79-
setLog($_SESSION['userID'],"Unrestricted image filename", "FAIL", date(dd-mm-yyyy), $privelige, "HIGH");
80-
81-
/*
82-
Set counter; if counter hits 3, the user's session must be terminated.
83-
After 3 session terminations the user acount should be blocked
84-
Since the high threat level there will be imediate session termination
85-
*/
86-
setCounter(3);
87-
88-
//The die function is to make sure the rest of the php code is not excecuted beyond this point
89-
die();
90-
}
84+
//then we return true
85+
return true;
9186
}
87+
88+
}
89+
}
90+
91+
//Here we handle the consequences if the checkpattern function fails
92+
if(checkpattern() !== true){
93+
94+
//Set a log for whenever there is unexpected user input with a threat level:
95+
setLog($_SESSION['userID'],"Detection of malicous input in file include", "FAIL", date(dd-mm-yyyy), $privelige, "HIGH");
96+
97+
/*
98+
If the user tries to read files other than specified, immediate logout wil follow!
99+
*/
100+
setCounter(3);
101+
102+
//The die function is to make sure the rest of the php code is not excecuted beyond this point
103+
die();
104+
}
105+
92106
93107
//if all goes wel upload your file, first we want to log the event.
94108
setLog($_SESSION['userID'],"File upload", "SUCCESS", date(dd-mm-yyyy), $privelige, "NULL");

skf/markdown/code_examples/php/13-code_example--Secure_session_cookies--.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Secure session cookies
2525

2626
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
2727
}
28+
29+
/*
30+
You could also set the session cookie its secure function with a ini_set
31+
This ini_set has to be included in the header of al your pages in order to work
32+
*/
33+
34+
ini_set('session.cookie_secure', 1);
2835

2936
?>
3037

skf/markdown/code_examples/php/14-code_example--Session_cookies_HttpOnly--.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@ Session cookies HttpOnly
2020

2121
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
2222
}
23+
24+
/*
25+
You could also set the session cookie its httpOnly function with a ini_set
26+
This ini_set has to be included in the header of al your pages in order to work
27+
*/
28+
29+
ini_set('session.cookie_httponly', 1);
30+
31+
2332

2433
?>

skf/markdown/code_examples/php/15-code_example--Identifier_based_authorization--.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,37 @@ Identifier-based authorization
2424
}
2525

2626

27-
//The seccond layer is to define the allowed pages to be read by the user
28-
$array = array("/page1/" ,"/page2/" ,"/etc/" ,"/etc/");
27+
//First we create a function which checks te allowed patterns
28+
function checkpattern(){
29+
$array = array("/^page1$/" ,"/^page2$/" ,"/^etc$/" ,"/^etc$/");
2930

30-
foreach($array as $page){
31-
while(!preg_match($page , $_GET['page']])){
31+
foreach($array as $Pattern){
32+
while(preg_match($Pattern , $_GET['page'])){
33+
//If the value is valid we send a log to the logging file.
34+
setLog($_SESSION['userID'],"Validation was succesfull for filename", "SUCCESS", date(dd-mm-yyyy), $privelige, "NULL");
35+
36+
//then we return true
37+
return true;
38+
}
39+
40+
}
41+
}
42+
43+
//Here we handle the consequences if the checkpattern function fails
44+
if(checkpattern() !== true){
3245
3346
//Set a log for whenever there is unexpected user input with a threat level:
3447
setLog($_SESSION['userID'],"Detection of malicous input in file include", "FAIL", date(dd-mm-yyyy), $privelige, "HIGH");
3548
3649
/*
37-
If the user tries to read files pages than specified, immediate logout wil follow!
38-
50+
If the user tries to read files other than specified, immediate logout wil follow!
3951
*/
4052
setCounter(3);
41-
53+
4254
//The die function is to make sure the rest of the php code is not excecuted beyond this point
43-
die();
44-
}
55+
die();
4556
}
57+
4658

4759

4860
/*

skf/markdown/code_examples/php/20-code_example--Timeout_a_session--.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Timeout a session
1919
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
2020

2121
}
22+
23+
/*
24+
You could also set the session cookie its secure function with a ini_set
25+
This ini_set has to be included in the header of al your pages in order to work
26+
*/
27+
28+
ini_set('session.cookie_lifetime', 3600);
2229

2330
?>
2431

skf/markdown/code_examples/php/25-code_example--Login_functionality--.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Debug Enabling
1111
For privilege based authentication we need an extra tabel in your database in order to write the users privileges to.
1212

1313
TABLE users
14-
-------------------------------------------------------------
15-
| userID | userName | password | privilegeID | access |
16-
-------------------------------------------------------------
17-
| 1 | Admin | Csdar323 | 1 | TRUE |
18-
-------------------------------------------------------------
19-
| 2 | User | Adf4fsv | 2 | FALSE |
20-
-------------------------------------------------------------
21-
| 3 | Guest | dff4fKr | 3 | TRUE |
22-
-------------------------------------------------------------
14+
---------------------------------------------------------------------------------
15+
| userID | userName | password | privilegeID | access | AggregrateControl |
16+
---------------------------------------------------------------------------------
17+
| 1 | Admin | Csdar323 | 1 | TRUE | 2336 |
18+
---------------------------------------------------------------------------------
19+
| 2 | User | Adf4fsv | 2 | FALSE | 0 |
20+
---------------------------------------------------------------------------------
21+
| 3 | Guest | dff4fKr | 3 | TRUE | 135 |
22+
---------------------------------------------------------------------------------
2323

2424
TABLE privileges
2525
----------------------------------
@@ -45,7 +45,7 @@ Debug Enabling
4545
In this example the expexted input is "a-Z/0-9 - _"
4646
*/
4747

48-
if(!preg_match("/^[^a-zA-Z0-9_\-]/", $username))
48+
if(preg_match("/[^a-zA-Z0-9]/", $username))
4949
{
5050
//Set a log for whenever there is unexpected userinput with a threat level
5151
setLog("null","invalid expected input", "FAIL", date(dd-mm-yyyy), "null", "HIGH");
@@ -106,7 +106,7 @@ Debug Enabling
106106
/*
107107
This is how you enforce the permissions in your application
108108
We define the roles we want the user to suffice
109-
/*
109+
*/
110110

111111
if(isAuthorized("edit:read:delete") === true){
112112
//Do your operation

skf/markdown/code_examples/php/32-code_example--Input_validation--.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ input validation
1313
we can assume a hacker is trying to inject malicious input
1414
*/
1515
16-
if(!preg_match("/^[a-zA-Z0-9]+$/", $_POST['userinput'])
16+
if(!preg_match("/^[a-zA-Z0-9]+$/", $_POST['userinput']))
1717
{
1818
//Set a log for whenever there is unexpected userinput with a threat level
1919
setLog($_SESSION['userID'],"invalid expected input", "FAIL", date(dd-mm-yyyy), $privelige, "MOD");
@@ -31,35 +31,38 @@ input validation
3131
fixed expected value. whenever these value's differ from your fixed value's you can determin the user is tampering
3232
the value's and should be blocked since he is probably intercepting your parameters with an intercepting proxy.
3333
*/
34-
$array = array("/page1/" ,"/page2/" ,"/etc/" ,"/etc/");
35-
36-
foreach($array as $injectPattern){
37-
while(preg_match($injectPattern , $_GET['fileName']])){
38-
39-
//If the value is valid we send a log to the logging file.
40-
setLog($_SESSION['userID'],"Validation was succesfull for filename", "SUCCESS", date(dd-mm-yyyy), $privelige, "NULL");
41-
42-
//Then we return true value
43-
$bool = true;
44-
return $bool;
45-
}
46-
}
47-
48-
//If the value was not validated as true we must log and count the users actions
49-
if($bool !== true){
50-
51-
//Set a log for whenever there is unexpected user input with a threat level:
52-
setLog($_SESSION['userID'],"Detection of malicous input in file include", "FAIL", date(dd-mm-yyyy), $privelige, "HIGH");
53-
34+
35+
//First we create a function which checks te allowed patterns
36+
function checkpattern(){
37+
$array = array("/^page1$/" ,"/^page2$/" ,"/^etc$/" ,"/^etc$/");
38+
39+
foreach($array as $Pattern){
40+
while(preg_match($Pattern , $_GET['fileName'])){
41+
//If the value is valid we send a log to the logging file.
42+
setLog($_SESSION['userID'],"Validation was succesfull for filename", "SUCCESS", date(dd-mm-yyyy), $privelige, "NULL");
5443
55-
/*
56-
If the user tries to read files other than specified, immediate logout wil follow!
57-
*/
58-
setCounter(3);
59-
60-
//The die function is to make sure the rest of the php code is not excecuted beyond this point
61-
die();
62-
}
44+
//then we return true
45+
return true;
46+
}
47+
48+
}
49+
}
50+
51+
//Here we handle the consequences if the checkpattern function fails
52+
if(checkpattern() !== true){
53+
54+
//Set a log for whenever there is unexpected user input with a threat level:
55+
setLog($_SESSION['userID'],"Detection of malicous input in file include", "FAIL", date(dd-mm-yyyy), $privelige, "HIGH");
56+
57+
/*
58+
If the user tries to read files other than specified, immediate logout wil follow!
59+
*/
60+
setCounter(3);
61+
62+
//The die function is to make sure the rest of the php code is not excecuted beyond this point
63+
die();
64+
}
65+
6366
6467
/*
6568
Third example is an encoding routine where we take possible malicious input and transform it into harmless input.

skf/markdown/code_examples/php/32-code_example--Input_validation_validation--.md

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)