Sql Dosyasındaki Sorguları Alma ve Sıkıştırma

PHP
29 lines
<?php
class sorguCikarici{
private $dosyaAdi;
private $icerik;
public $sqlSorgulari;
public function __construct($dosyaYeri = ''){
if(strlen($dosyaYeri) < 1){
$this->dosyaAdi = '';
}else{
$this->dosyaAdi = $dosyaYeri;
}
}
public function sorgulariCikart(){
$sql=file($this->dosyaAdi);
foreach($sql as $s){
$ek=substr($s, 0, 2);
if(($ek != "--" and $ek != "/*") AND $s != "\n"){
$this->icerik.=$s;
}
}
$this->icerik=trim(preg_replace('/\s\s+/', ' ', $this->icerik));
$this->icerik = preg_replace('~[\r\n]+~', '', $this->icerik);
file_put_contents($this->dosyaAdi,$this->icerik);
return $this->icerik;
}
}
$sc = new sorguCikarici(dirname(__FILE__)."/data.sql");
$sc->sorgulariCikart();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Örnek data.sql

SQL
83 lines
-- phpMyAdmin SQL Dump
-- version 4.1.4
-- http://www.phpmyadmin.net
--
-- Anamakine: 127.0.0.1
-- Üretim Zamanı: 02 Haz 2018, 00:41:47
-- Sunucu sürümü: 5.6.15-log
-- PHP Sürümü: 5.4.24
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Veritabanı: `destek`
--
-- --------------------------------------------------------
--
-- Tablo için tablo yapısı `mesajlar`
--
CREATE TABLE IF NOT EXISTS `mesajlar` (
`mno` int(10) unsigned NOT NULL AUTO_INCREMENT,
`kim` int(11) DEFAULT NULL,
`zaman` datetime DEFAULT NULL,
`ticketid` int(60) DEFAULT NULL,
`mesaj` text CHARACTER SET latin5 NOT NULL,
`y` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`mno`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Tablo için tablo yapısı `urunler`
--
CREATE TABLE IF NOT EXISTS `urunler` (
`uno` int(10) unsigned NOT NULL AUTO_INCREMENT,
`urun_adi` text CHARACTER SET latin5,
`urun_fiyat` int(4) DEFAULT NULL,
`urun_kimin` int(4) DEFAULT NULL,
`urun_durumu` int(11) DEFAULT '0',
`urun_bilgisi` text CHARACTER SET latin5,
`urun_aciklama` text CHARACTER SET latin5,
`urun_bitistarihi` date DEFAULT NULL,
`urun_odemedurumu` int(1) NOT NULL DEFAULT '1',
`urun_sipariszamani` datetime NOT NULL,
`urun_alistarihi` date DEFAULT NULL,
PRIMARY KEY (`uno`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Tablo için tablo yapısı `uyeler`
--
CREATE TABLE IF NOT EXISTS `uyeler` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`kadi` varchar(15) DEFAULT NULL,
`tel` varchar(11) DEFAULT NULL,
`sifre` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Tablo döküm verisi `uyeler`
--
INSERT INTO `uyeler` (`id`, `kadi`, `tel`, `sifre`) VALUES
(1, 'admin', '5420', '14e1b6');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı data.sql

SQL
1 lines
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";SET time_zone = "+00:00";CREATE TABLE IF NOT EXISTS `mesajlar` ( `mno` int(10) unsigned NOT NULL AUTO_INCREMENT, `kim` int(11) DEFAULT NULL, `zaman` datetime DEFAULT NULL, `ticketid` int(60) DEFAULT NULL, `mesaj` text CHARACTER SET latin5 NOT NULL, `y` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`mno`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;CREATE TABLE IF NOT EXISTS `urunler` ( `uno` int(10) unsigned NOT NULL AUTO_INCREMENT, `urun_adi` text CHARACTER SET latin5, `urun_fiyat` int(4) DEFAULT NULL, `urun_kimin` int(4) DEFAULT NULL, `urun_durumu` int(11) DEFAULT '0', `urun_bilgisi` text CHARACTER SET latin5, `urun_aciklama` text CHARACTER SET latin5, `urun_bitistarihi` date DEFAULT NULL, `urun_odemedurumu` int(1) NOT NULL DEFAULT '1', `urun_sipariszamani` datetime NOT NULL, `urun_alistarihi` date DEFAULT NULL, PRIMARY KEY (`uno`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;CREATE TABLE IF NOT EXISTS `uyeler` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `kadi` varchar(15) DEFAULT NULL, `tel` varchar(11) DEFAULT NULL, `sifre` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;INSERT INTO `uyeler` (`id`, `kadi`, `tel`, `sifre`) VALUES(1, 'admin', '5420', '14e1b6');
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

SQL Enjeksiyon Kaldırma

PHP
67 lines
<?php
class sql{
public function enjeksiyonKaldir($string){
$injections = array(">", "<", "=", "'", "?", "\\", "/",
"&", "|","-", "+", "%", "$", "#", "*",
"or", "and", "drop", "insert", "rename", "select");
$string = str_replace($injections, "", htmlentities(strtolower($string),ENT_QUOTES,"UTF-8"));
return $string;
}
}
$s=new sql;
echo $s->enjeksiyonKaldir("''Or'='Or''");
echo "<br>";
echo $s->enjeksiyonKaldir("anything' OR 'x'='x");
echo "<br>";
echo $s->enjeksiyonKaldir("1'or'1'='1");
echo "<br>";
echo $s->enjeksiyonKaldir("' or 1=1 or ''='");
echo "<br>";
echo $s->enjeksiyonKaldir("\" or 1=1 or \"\"=\"");
echo "<br>";
echo $s->enjeksiyonKaldir("' OR ''='");
echo "<br>";
echo $s->enjeksiyonKaldir("'' OR ''=''");
echo "<br>";
echo $s->enjeksiyonKaldir("'OR''='");
echo "<br>";
echo $s->enjeksiyonKaldir("hey' or 1=1–");
echo "<br>";
echo $s->enjeksiyonKaldir("''Or 1 = 1'");
echo "<br>";
echo $s->enjeksiyonKaldir("' or 1=1-- ");
echo "<br>";
echo $s->enjeksiyonKaldir("or 1=1--");
echo "<br>";
echo $s->enjeksiyonKaldir("\" or 1=1--");
echo "<br>";
echo $s->enjeksiyonKaldir("or 1=1--");
echo "<br>";
echo $s->enjeksiyonKaldir("' or 'a'='a");
echo "<br>";
echo $s->enjeksiyonKaldir("\" or \"a\"=\"a");
echo "<br>";
echo $s->enjeksiyonKaldir("') or ('a'='a");
echo "<br>";
echo $s->enjeksiyonKaldir("hi\") or (\"a\"=\"a");
echo "<br>";
echo $s->enjeksiyonKaldir("'hi' or 'x'='x';");
echo "<br>";
echo $s->enjeksiyonKaldir("x' or 1=1 or 'x'='y");
echo "<br>";
echo $s->enjeksiyonKaldir("\x27\x4F\x52 SELECT *");
echo "<br>";
echo $s->enjeksiyonKaldir("\x27\x6F\x72 SELECT *");
echo "<br>";
echo $s->enjeksiyonKaldir("'or select *");
echo "<br>";
echo $s->enjeksiyonKaldir("admin'--");
echo "<br>";
echo $s->enjeksiyonKaldir("\")) or ((\"x\"))=((\"x");
echo "<br>";
echo $s->enjeksiyonKaldir("\" or \"\"+\"");
echo "<br>";
echo $s->enjeksiyonKaldir("admin\"or 1=1 or \"\"=\"");
echo "<br>";
echo $s->enjeksiyonKaldir("admin\") or (\"1\"=\"1\"--");
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
28 lines
039;039;039;039;039;039;
anything039; 039;x039;039;x
1039;039;1039;039;1
039; 11 039;039;039;
quot; 11 quot;quot;quot;
039; 039;039;039;
039;039; 039;039;039;039;
039;039;039;039;
hey039; 11ndash;
039;039; 1 1039;
039; 11·
11
quot; 11
11
039; 039;a039;039;a
quot; quot;aquot;quot;a
039;) (039;a039;039;a
hiquot;) (quot;aquot;quot;a
039;hi039; 039;x039;039;x039;;
x039; 11 039;x039;039;y
039;·
039;·
039;·
admin039;
quot;)) ((quot;xquot;))((quot;x
quot; quot;quot;quot;
adminquot; 11 quot;quot;quot;
adminquot;) (quot;1quot;quot;1quot;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Sql Katman Mysqli Veritabanı Sınıfı

PHP
80 lines
<?php
class SQLKatman {
var $sunucu;
var $kullaniciadi;
var $sifre;
var $veritabaniadi;
var $link;
function SQLKatman ($sunucu = "", $kullaniciadi = "", $pass = "", $veritabaniadi = "") {
$this->sunucu = $sunucu;
$this->kullaniciadi = $kullaniciadi;
$this->sifre = $pass;
$this->veritabaniadi = $veritabaniadi;
$this->baglan();
}
function baglan(){
$this->link=mysqli_connect($this->sunucu,$this->kullaniciadi,$this->sifre,$this->veritabaniadi);
mysqli_set_charset($this->link, "utf8");
}
function close(){
return mysqli_close($this->link);
}
function sorgu($sorgu){
$this->rs=mysqli_query($this->link,$sorgu);
if (!$this->rs){
echo("Hata: Hatalı sorgu \"".$sorgu."\"...<br>");
echo("Hata: ".mysqli_errno($this->link)."<br>");
die("Hata: ".mysqli_error($this->link)."<br>");
}else{
return $this->rs;
}
}
function veri_ara ($row = 0) {
return mysqli_data_seek($this->rs,$row);
}
function dizi_getir($rs=""){
if($rs==""){$rs=$this->rs;}
$this->row=mysqli_fetch_array($rs);
return $this->row;
}
function birles_getir($rs=""){
if($rs==""){$rs=$this->rs;}
$this->row=mysqli_fetch_assoc($rs);
return $this->row;
}
function nesne_getir($rs=""){
if($rs==""){$rs=$this->rs;}
$this->row=mysqli_fetch_object($rs);
return $this->row;
}
function satir_say($rs=""){
if($rs == ""){$rs=$this->rs;}
$rs = $this->rs;
return mysqli_num_rows($rs);
}
function etkilenen_satir() {
return mysqli_affected_rows($this->link);
}
function serbest_sonuc($rs = "") {
if($rs == ""){$rs=$this->rs;}
$rs = $this->rs;
return mysqli_free_result($rs);
}
}
$s=new SQLKatman("localhost","root","","php");
$s->sorgu("select * from php where id=1");
print_r($s->dizi_getir());echo "<br>";
$s->sorgu("select * from php where id=1");
print_r($s->birles_getir());echo "<br>";
$s->sorgu("select * from php where id=1");
print_r($s->nesne_getir());echo "<br>";
$s->sorgu("select * from php where id=1");
print_r($s->satir_say());echo "<br>";
$s->sorgu("select * from php where id=1");
print_r($s->etkilenen_satir());echo "<br>";
$s->sorgu("select * from php where id=1");
print_r($s->serbest_sonuc());
$s->sorgu("select * from php where id=1");
var_dump($s->veri_ara(2));
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

PHP
6 lines
Array ( [0] => 1 [id] => 1 )
Array ( [id] => 1 )
stdClass Object ( [id] => 1 )
1
1
bool(false)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX