Skip to content

Instantly share code, notes, and snippets.

View kcyeu's full-sized avatar

Kuo-Cheng Yeu kcyeu

View GitHub Profile
@kcyeu
kcyeu / docker-rmii.sh
Created February 18, 2015 06:33
Docker one-liner - batch remove intermediate images
sudo docker rmi `docker images | awk '($1 ~ /<none>/) {print $3}' | xargs`
@kcyeu
kcyeu / Preferences.sublime-settings
Created February 13, 2015 16:14
My Sublime Text Configuration
{
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme",
"font_face": "Consolas",
"font_size": 20,
"ignored_packages":
[
"Vintage"
]
}
@kcyeu
kcyeu / Install docker-compose
Created February 7, 2015 09:32
Install docker-compose one liner
curl -L https://github.com/docker/fig/releases/download/1.1.0-rc2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose; chmod +x /usr/local/bin/docker-compose
@kcyeu
kcyeu / register_globals-15-16.php
Created December 9, 2014 10:13
Example 15-16. Detecting simple variable poisoning
<?php
if (isset($_COOKIE['MAGIC_COOKIE'])) {
// MAGIC_COOKIE comes from a cookie.
// Be sure to validate the cookie data!
} elseif (isset($_GET['MAGIC_COOKIE']) || isset($_POST['MAGIC_COOKIE'])) {
mail("admin@example.com", "Possible breakin attempt", $_SERVER['REMOTE_ADDR']);
echo "Security violation, admin has been alerted.";
exit;
} else {
@kcyeu
kcyeu / register_globals-15-15.php
Created December 9, 2014 10:12
Example 15-15. Example use of sessions with register_globals on or off
<?php
// We wouldn't know where $username came from but do know $_SESSION is
// for session data
if (isset($_SESSION['username'])) {
echo "Hello <b>{$_SESSION['username']}</b>";
} else {
echo "Hello <b>Guest</b><br />";
echo "Would you like to login?";
}
?>
@kcyeu
kcyeu / register_globals-15-14.php
Last active August 29, 2015 14:11
Example 15-14. Example misuse with register_globals = on
<?php
// define $authorized = true only if user is authenticated
if (authenticated_user()) {
$authorized = true;
}
// Because we didn't first initialize $authorized as false, this might be
// defined through register_globals, like from GET auth.php?authorized=1
// So, anyone can be seen as authenticated!
if ($authorized) {
include "/highly/sensitive/data.php";
@kcyeu
kcyeu / php-ftp-auth.php
Last active August 29, 2015 14:10
PHP FTP Authentication
<?php
function CheckFTP($server, $id, $passwd, $port = 21)
{
//若任一欄位為空白則無效
if (empty($server) || empty($id) || empty($passwd))
return false;
//連結FTP Server
$fs = fsockopen ($server, $port, &$errno, &$errstr, 5);
@kcyeu
kcyeu / php-pop3-auth.php
Last active January 9, 2018 08:19
PHP POP3 Authentication
<?php
function CheckPOP3($server, $id, $passwd, $port = 110)
{
//若任一欄位為空白則無效
if (empty($server) || empty($id) || empty($passwd))
return false;
// connect to POP3 Server
$fs = fsockopen ($server, $port, &$errno, &$errstr, 5);
@kcyeu
kcyeu / PHP4 Pagination 2-2.php
Created December 1, 2014 15:37
PoC of PHP4 pagination, footer part.
<table width="400" align="center">
<tr>
<td><?echo "共".$totalpage."頁,現在是第".$page."頁";?>
</td>
<td>
<a href="<?=$PHP_SELF?>?page=1"title="最首頁">最首頁</a>
<?
if($page-$front_back<=1){
$front=1;
}else{
@kcyeu
kcyeu / PHP4 Pagination 2-1.php
Created December 1, 2014 15:36
PoC of PHP4 pagination, header part.
<?php
include("../config.php");
$result = mysql_query("SELECT * FROM member");
$total = mysql_num_rows($result);
if(!isset($page)) (int)$page=1; //若無設定$page, 則預設為1
$page_num = 2; //每頁設定顯示筆數
$front_back = 2;
$begin = ($page-1) * $page_num;