PHP gzdeflate+str_to13+pack的一种加密解密代码方式

首先我们要加密的明文是: $test=<<<'EVE' echo '<script>alert("nihao")</script>';die; EVE; 字符串转16进制,16进制还原的方法 function String2Hex($string){     $hex='';     for ($i=0; $i < strlen($string); $i++){         $hex .= dechex(ord($string[$i]));     }     return $hex; } function Hex2String($hex){     $string='';     for ($i=0; $i < strlen($hex)-1; $i+=2){         $string .= chr(hexdec($hex[$i].$hex[$i+1]));     }     return $string; } 加密: $test1= gzdeflate($test);   #压缩$test1=base64_encode($test1); #转码$adam=String2Hex(str_rot13($test1)); #rot13+16进制转换 加密后的字符串: 463033426c537144676c794259666266585953596d527867586753446c66695a465a6b4b30654745756a64654a367178637962514e4e3d3d 解密: $ev=str_rot13(pack("H*",$adam)); $decoded=gzinflate(base64_decode($ev));

TP5.0和TP5.1 rce远程代码执行漏洞

上午同事发现官网被挂马了,title keywords和description都被改了,网站一句tp5开发的,前几天正好看到TP官方发布了一个安全补丁,阿里云也在提示,就看了下,大概是对controller没有严格过滤导致,影响的有TP,thinkcmf,DolphinPHP等 攻击例子: index.php?s=portal/thinkapp/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][0]=/home/wwwroot/demo/public/adam1.txt&vars[1][1]=aaaa 会在public目录下创建adam1.txt文件并写入内容,网上也发布了很多分析漏洞的文章。 https://www.kingkk.com/2018/12/ThinkPHP5-x-%E5%89%8D%E5%8F%B0getshell%E5%88%86%E6%9E%90/ http://www.lsablog.com/networksec/penetration/thinkphp5-rce-analysis/ 这个漏洞影响太大了,得赶紧修复,不能忽略。。 修复方式参考tp官方:https://blog.thinkphp.cn/869075

PHP利用反射获取class method 和function的源码

反射获取function源码  继承ReflectionFunction,扩展getSource方法: <?php /*     ___        __                   _        ____   ____     /   |  ____/ /____ _ ____ ___   (_)____  / __  / __    / /| | / __  // __ `// __ `__  / // __ / /_/ // / / /  / ___ |/ /_/ // /_/ // / / / / // // / / /__, // /_/ /  /_/  |_|__,_/ __,_//_/ /_/ /_//_//_/ /_//____/ ____/                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                  做一款产品       愉悦自己                 ****************Powered by Adamin90******************** * @email: 14846869@qq.com * Date: 2018/12/27 * Time: 20:00 * @link: https://www.lixiaopeng.top ******************************************************* */ namespace appcommonlogic; class FunctionExtract  extends ReflectionFunction {     /**      * @return bool|string      * @author Adam      * Time: 2018/12/27 20:30      * Description:获取function源码       */     public function  getSource(){         if(!file_exists($this->getFileName())){             return false;         }         $startoffset=$this->getStartLine()-1;         $endoffset=$this->getEndLine()-$this->getStartLine()+1;         //   return $this->getFileName();         return join('',array_slice(file($this->getFileName()),$startoffset,$endoffset));     }     public function index(){         echo $this->getSource('id_decode');     } } 使用方法: 实例化 FunctionExtract类,构造器传入funtion名称即可 $fc = new FunctionExtract("get_avatar"); echo $fc->getSource(); 输出结果: function get_avatar($uid) { $avatar = Db::name('user')->where('id', $uid)->value('avatar'); if (!empty($avatar)) { $path = get_file_path($avatar); if($path !== false) { return $path; } } //默认头像地址 return '/static/mobile/images/avatar.jpg'; } 反射获取Method源码  继承ReflectionMethod,自定义getSource方法 class MethodExtract  extends ReflectionMethod {     /**      * @return bool|string      * @author Adam … Read more

零散知识备忘

进制转换:  PHP:  bin(二进制) oct(八进制) hex(十六进制)  dec(十进制) binhex()  #二进制转十六进制 hexbin()  #十六进制转二进制 ….. 以此类推 base_convert(string $number,int $frombase, int $tobase)  #参数分别是  要转化的数,原始进制,要转换成的进制。 查看crontab状态: service cron status Windows 查看内存: #总内存 cmd下:  wmic ComputerSystem get TotalPhysicalMemory    // Get total physical memory (this is in bytes) php代码调用:  $cmd = "wmic ComputerSystem get TotalPhysicalMemory";             @exec($cmd, $outputTotalPhysicalMemory);              #剩余内存 cmd下   wmic OS get FreePhysicalMemory   //Get free physical memory (this is in kibibytes!) linux下查看内存: cat /proc/meminfo PHP memory_get_peak_usage和memory_get_usage区别: memory_get_peak_usage返回分配给php内存的峰值,memory_get_usage返回脚本执行分配给php的总内存  两盒单位都是byte PHP byte转换成 kb Mb  Gb Tb Pb的简单方式  //$size 单位byte function convert($size) {     $unit=array('b','kb','mb','gb','tb','pb');     return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } PHP yield 生成斐波那契数列 function getFibonacci() {     $i = 0;     $k = 1; //first fibonacci value     yield $k;     while(true)     {         $k = $i + $k;         $i = $k – $i;         yield $k;             } … Read more

Centos 查看端口号占用进程

lsof lsof  -h #查看帮助 lsof 4.82  latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/  latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ  latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man  usage: [-?abhlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]  [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s] [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [–] [names] Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.   -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks   -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)   +d s  dir s files        -d s  select by FD set     +D D  dir D tree *SLOW?*                            +|-e s  exempt s *RISKY*   -i select IPv[46] files   -l list UID numbers      -n no host names           -N select NFS files   -o list file offset      -O avoid overhead *RISKY*  -P no port names   -R list paRent PID       -s list file size          -t terse listing   -T disable TCP/TPI info  -U select Unix socket      -v list version info   -V verbose search        +|-w  Warnings (+)         -X skip TCP&UDP* files   -Z Z  context [Z]   — end option scan   +f|-f  +filesystem or -file names     +|-f[gG] flaGs   -F [f] select fields; -F? for help   +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)                                         +m [m] use|create mount supplement   +|-M   portMap registration (-)       -o o   o 0t offset digits (8)   -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)   -T qs TCP/TPI Q,St (s) info   -g [s] exclude(^)|select and print process group IDs   -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]   +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, – forever.        An optional suffix to t is m<fmt>; m must separate t from <fmt> and       <fmt> is an strftime(3) format for the marker line.   -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).   -u s   exclude(^)|select login|UID set s   -x [fl] cross over +d|+D File systems or symbolic Links   names  select named files or files on named file systems Anyone can list all files; /dev warnings disabled; kernel ID check disabled. lsof -i #列出所有网络链接 lsof -i tcp #列出所有tcp连接   lsof -i :3306 #列出谁在使用3306端口 lsof -p 12222 #通过进程号 查看该进程打开的文件 netstat -anp|grep 3306 tcp6       0      0 :::3306                 :::*                    LISTEN      14364/mysqld

mysql开启慢查询日志

vi /etc/my.cnf 在 [mysqld] 下加入 slow_query_log = 1  #开启慢查询日志 slow_query_log_file = /var/log/mysql-slow.log  #指定日志存放地址,mysql5.5及之前版本 log-slow-queries long_query_time = 1  #设置多久视为慢查询 chown mysql:mysql -R /var/log/musql-slow.log 重启mysql 查看设置的变量 mysql> show variables like '%slow%'; +—————————+————————-+ | Variable_name             | Value                   | +—————————+————————-+ | log_slow_admin_statements | OFF                     | | log_slow_slave_statements | OFF                     | | slow_launch_time          | 2                       | | slow_query_log            | ON                      | | slow_query_log_file       | /var/log/mysql-slow.log | +—————————+————————-+ 5 rows in set (0.00 sec) mysql> show variables like 'long_query_time'; +—————–+———-+ | Variable_name   | Value    | +—————–+———-+ | long_query_time | 1.000000 | +—————–+———-+ 1 row in set (0.00 sec) 模拟查询 SELECT SLEEP(5); 查看mysql-slow.log文件 /usr/local/mysql/bin/mysqld, Version: 5.6.40-log (Source distribution). started with: Tcp port: 3306  Unix socket: /tmp/mysql.sock Time                 Id Command    Argument # Time: 181127 19:07:05 # User@Host: root[root] @ localhost []  Id:     1 # Query_time: 5.000253  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0 SET timestamp=1543316825; select sleep(5); 查询mysql连接数 mysql> SHOW status like 'Threads%'; +——————-+——-+ | Variable_name     | Value | +——————-+——-+ | Threads_cached    | 1     | | Threads_connected | 1     | | Threads_created   | 2     | | Threads_running   | 1     | +——————-+——-+ 4 rows in set (0.00 sec) 查询mysql配置最大连接数 mysql> show variables like 'max_connections'; +—————–+——-+ | Variable_name   | Value | +—————–+——-+ … Read more

PHP面试基础–网络

TCP的三次握手四次挥手: 三次握手(Three-way handshake)(SYN,SYN-ACK,ACK)建立连接流程: Host A 发送一个请求(SYNchronize packet)给Host B Host B 接受A的SYN,接着发送一个确同步SYNchronize-ACKnowledgement给Host A Host A 接受B的SYN-ACK同步确认,发送确认接受请求ACK Host B 接口ACK  此后tcp socket connection进入ESTABLISHED状态  四次挥手,终止连接流程: 客户端发送FIN请求终止连接,同时client进入FIN-WAIT-1状态,此时客户端仍然能够接受服务端数据,但是已经无法访问本地数据发送给服务端 Server接受客户端发送的FIN信号,同时发送一个ACK确认信号,服务端进入CLOSE-WAIT状态 客户端接受ACK,等待服务器FIN信号,此时客户端进入FIN-WAIT-2状态 服务端等待程序执行完后发送FIN信号,服务端进入LAST-ACK状态 客户端接受FIN,返回ACK确认信号,客户端进入TIME-WAIT状态 TCP和UDP的区别和应用: TCP(Transmission controll protocol)传输控制协议,是互联网最普遍的协议,他的建立需要三次握手 UDP(User datagram protocol)用户报文协议,他的联系不需要服务端等待确认信息,会一直发送传输速率比TCP要快 TCP应用web浏览器,ssh等非常普遍,UDP应用于广播,游戏等场景 OSI七层架构和TCP/IP五层架构: OSI:应用层,表示层,会话层,传输层,网络层,数据链路层,物理层 TCP/IP:应用层,传输层,网络层,数据链路层,物理层

PHP面试基础之Array Functions

array_change_key_case:      把数组中所有键名称修改小写或大写,默认小写    2.array_chunk(array $array,int $size [, bool $preserve_keys=false])     把一个数组拆分成多个,第三个参数为true表示保留原来的键名    3.array_column(array $input,mixed $column_key [,$index_key=null)     返回数组中的单列,$column_key指返回哪列,$index_key如果设置了返回数组以其对应的值为返回数组的键    4.array_combile(array $keys,array $values)         数组结合    5.array_count_values(array $array)     计算数组内每个值的次数    6.array_diff_assoc ( array $array1 , array $array2 [, array $… ] ) 带索引计算数组的差集,返回$array1中有而$array2后面数组中没有的内容  7. array_diff_key ( array $array1 , array $array2 [, array $… ] ) 用键计算数组差集,返回一个数组,其key在$array1中存在,而在其他参数数组中不存在 8.array_diff_uassoc ( array $array1 , array $array2 [, array $… ], callable$key_compare_func ) 用用户提供的回调函数带索引计算数组的差集 9. array_diff_ukey ( array $array1 , array $array2 [, array $… ], callable$key_compare_func ) 用回调函数对键比较计算数组差集  10 array_diff ( array $array1 , array $array2 [, array $… ] ) 计算数组差集,返回在$array1中出现而在其他数组中不出现的数组,与array_diff_assoc区别在于不考虑索引 11.array array_fill_keys ( array $keys , mixed $value ) 用$keys的值作为key,$value的值作为值返回新数组,如果$value是关联数组,则全部返回作为值 12.array array_fill ( int $start_index , int $num , mixed $value ) 用$value的值填充长度为$num的数组,index从$start_index开始,如果$start_index是负数,则第一个键是$start_index,后面从0开始 13.array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] ) 用回调函数迭代过滤数组中的元素,如果不提供callback那么$array中值为false的都将被移除。flag默认是0表示只传递值比较,如果flag是ARRAY_FILTER_USE_KEY,那么只传递key给callback,如果是ARRAY_FILTER_USE_BOTH,那么key和value都传递

TP3.1迁移PHP7.2问题及解决办法

tp3.1程序放到php7.2环境下跑会直接报functions.php下112行未找到模块的错误,原因是preg_replace函数pattern中带/e在php7之后已经被移除不再支持 解决办法是用preg_replace_callback函数代替  其中涉及到的类有  ThinkTemplate.class.php  Dispatcher.class.php  common.php  下面贴出完整代码。 ThinkTemplate.class.php: <?php // +———————————————————————- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +———————————————————————- // | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved. // +———————————————————————- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +———————————————————————- // | Author: liu21st <liu21st@gmail.com> // +———————————————————————- /**  * ThinkPHP内置模板引擎类  * 支持XML标签和普通标签的模板解析  * 编译型模板引擎 支持动态缓存  * @category   Think  * @package  Think  * @subpackage  Template  * @author liu21st <liu21st@gmail.com>  */ class  ThinkTemplate {     // 模板页面中引入的标签库列表     protected   $tagLib          =   array();     // 当前模板文件     protected   $templateFile    =   '';     // 模板变量     public      $tVar            =   array();     public      $config          =   array();     private     $literal         =   array();     private     $block           =   array();     /**      * 架构函数      * @access public      */     public function __construct(){         $this->config['cache_path']         =   C('CACHE_PATH');         $this->config['template_suffix']    =   C('TMPL_TEMPLATE_SUFFIX');         $this->config['cache_suffix']       =   C('TMPL_CACHFILE_SUFFIX');         $this->config['tmpl_cache']         =   C('TMPL_CACHE_ON');         $this->config['cache_time']         =   C('TMPL_CACHE_TIME');         $this->config['taglib_begin']       =   $this->stripPreg(C('TAGLIB_BEGIN'));         $this->config['taglib_end']         =   $this->stripPreg(C('TAGLIB_END'));         $this->config['tmpl_begin']         =   $this->stripPreg(C('TMPL_L_DELIM'));         $this->config['tmpl_end']           =   $this->stripPreg(C('TMPL_R_DELIM'));         $this->config['default_tmpl']       =   C('TEMPLATE_NAME');         $this->config['layout_item']        =   C('TMPL_LAYOUT_ITEM');     }     private function stripPreg($str) { … Read more