PHP静态分析与跨站脚本检测(四)

 更新时间:2016年11月25日 16:10  点击:1596
今天继续提交读程序笔记,这次比较少,而且相对简单些。

ConnectorComputation
    - compute()
        如果workList还有元素,就继续循环,但是第一次进入循环时候根据构造方法来看workList只有一个元素<mainFunction, emptyCallString>。然后从workList中取出第一个元素,获取TacFunction和CallString(gamma),根据TacFunction(p)从function2ECS中得到ECS(ecs_p),实际上此时functions2ECS中第一个元素对应的TacFunction即为_main。得到gamma在ecs_p中的位置,即是在一个CallString的链表中的位置
        随后,将p这个TacFunction包含的所有的CfgNodeCall迭代一遍,对于每一个callNode,得到其callee(即被调用的函数q),在q!=null的情况下,以callNode建立一个新的CallString(gamma_2),从function2ECS中得到q对应的ECS(ecs_q),获取ecs_q中gamma_2的位置,如果为-1,就将gamma_2添加到ecs_q的CallStrings队列中去,并以q和gamma_2建立元素添加到workList中去,expand it。
        接下来扩充什么ConnectorFunction因为都在for循环里边,是对局部变量的操作,所以没有什么用处。
        在while循环结束之后,调用makeCallGraph()方法。
    - makeCallGraph()
        首先以mainFunction初始化一个CallGraph,获得mainFunction所包含的方法调用列表processUs<CfgNodeCall>,并建立一个以访问的集合visited,将mainFunction添加进集合里边。
        当processUs不为空,依次取出元素callNode,得到它的caller和callee,如果callee!=null,向callGraph中添加元素。如果callee还没有被处理过,则将其所包含的所有函数调用添加进processUs,并将其放进visited。


Checker
    根据初始提供的run-all.bat的参数来看,实际上aliases analyze和literal analyze并没有进行,只是gta.analyze()进行了,实际上也就是只有dependance analyze执行了。通过以来关系最后决定vulns。

 最近在看PHP静态分析与跨站脚本检测的东西,用的是维也纳大学一个博士生做出来的Pixy,这个东西是开源的,而且也作了好几年了,功能逐渐增强。现在这个3.0.3版本里边有225个程序,Checker是主程序,现在所有结果都是显示在命令行的,如果被检测程序大,结果很多,当然是个问题。而我要做的大概是将其显示到GUI中去,并且改进它本身呈鼓里边一些不足的地方。
从寒假就开始看他的程序,寒假里边没有怎么搞明白,又冷,手生冻疮了。回来以后,从头开始看吧,分析那一部分不是很明白,但是看到后来,检测漏洞的时候,我想暂时不管它存储的结构什么,反正都是Node之类的东西,看他是怎么检测的,有的细节地方那个暂时翻过去,结果感觉比前边analysze部分简单得多了,连那些存储结构什么的都明白些了。
当然也看他的论文,论文换了一个寒假看完,没弄明白,像Cfg这些东西在论文中有,但是显示不出来,没有直观的感觉,不爽。所以这两天忙着弄了个GUI界面来显示这个Cfg控制流图,麻烦了一点,不过总算是出来了,看看好像也没有多大问题,献丑在这里了。另外,本来是自己使用的,有的地方考虑不周也无所谓,自己再调调就行了。
共有3个文件,第一个是Coor.java,保存每个节点的坐标以及其子节点坐标:


package at.ac.tuwien.infosys.www.pixy;

import java.util.*;
public class Coor 
{
    
private int x;
    
private int y;
    
private List<Coor> coors;
    
public Coor(int x, int y)
    
{
        
this.coors = new LinkedList<Coor>();
        
this.x = x;
        
this.y = y;
    }

    
public int getX()
    
{
        
return this.x;
    }

    
public int getY()
    
{
        
return this.y;
    }

    
public List<Coor> getCoors()
    
{
        
return this.coors;
    }

    
public void addCoor(Coor coor)
    
{
        
this.coors.add(coor);
    }

    
public boolean equals(Coor coor)
    
{
        
if (coor.getX()==this.x && coor.getY()==y)
        
{
            
return true;
        }

        
return false;
    }

    
public boolean contains(Coor c)
    
{
        
for (Coor coor : this.coors)
        
{
            
if (coor.getX()==c.getX() && coor.getY()==c.getY())
            
{
                
return true;
            }

        }

        
return false;
    }

}



第二个是DrawPanel.java,负责画图的组件:


package at.ac.tuwien.infosys.www.pixy;
import at.ac.tuwien.infosys.www.pixy.conversion.Cfg;
import at.ac.tuwien.infosys.www.pixy.conversion.nodes.*;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 *
 * 
@author Administrator
 
*/

public class DrawPanel extends JPanel
{
    
private java.util.List<CfgNode> cfgList;
    
private java.util.List<Coor> coorList;
    
    
/** Creates a new instance of OvalJPanel */
    
public DrawPanel(java.util.List<CfgNode> cfgList, java.util.List<Coor> coorList) 
    
{
        
this.cfgList = cfgList;
        
this.coorList = coorList;
    }

    
//在面板上绘制图形
    public void paintComponent(Graphics g)
    
{
        
        
        
for (int i=0 ;i<this.cfgList.size() ;i++ )
        
{
            CfgNode cfgNode 
= this.cfgList.get(i);
            Coor coor 
= this.coorList.get(i);
            
int x = coor.getX();
            
int y = coor.getY();
            g.setColor(Color.red);
            g.drawOval(x
-50, y-1510030);
            g.setColor(Color.blue);
            g.drawString(cfgNode.toString(), x
-30, y-5);
            g.drawString(
"Loc :" + String.valueOf(cfgNode.getOrigLineno()), x, y+10);
            java.util.List
<Coor> coors = coor.getCoors();
            
for (Coor c : coors)
            
{
                
int cx = c.getX();
                
int cy = c.getY();
                g.setColor(Color.black);
                
if (c.equals(coor))
                
{
                    g.setColor(Color.yellow);
                }

                g.drawLine(x, y
+15, cx, cy-15);
                
            }

        }

    }

}




第三个是Draw.java,主控制组件,只需要在Checker中调用该类,传以适当参数(Cfg),就可以了。


package at.ac.tuwien.infosys.www.pixy;
import at.ac.tuwien.infosys.www.pixy.conversion.Cfg;
import at.ac.tuwien.infosys.www.pixy.conversion.nodes.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
/**
 *
 * 
@author Administrator
 
*/

public class Draw {
    
    
//声明框架
    private JFrame frame = new JFrame("Control Flow Graph");
    
//声明书签面板
    private DrawPanel draw;
    
private Cfg cfg;
    
private Map<CfgNode, Coor> map;
    
private java.util.List<CfgNode> cfgList;
    
private java.util.List<Coor> coorList;
    
private int startX = 50;
    
private int startY = 30;

    
/** Creates a new instance of TabbedJFrame */
    
public Draw(Cfg cfg) {
        
//this.map = new TreeMap<CfgNode, Coor>();
        this.cfgList = new LinkedList<CfgNode>();
        
this.coorList = new LinkedList<Coor>();
        
this.cfg = cfg;
    }

    
public void show()
    
{
        frame.add(
new JScrollPane(new DrawPanel(this.cfgList, this.coorList)), BorderLayout.CENTER);
        frame.setSize(
10001000);
        frame.setLocation(
5050);
        frame.setVisible(
true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    
/**
     * 将Cfg转换为cfgList和coorList.
     
*/

    
public void convert()
    
{
        CfgNode node 
= this.cfg.getHead();
        
int size = this.cfg.size();
        Coor coor 
= new Coor(startX, startY);

        
this.cfgList.add(node);
        
this.coorList.add(coor);
        System.out.println(size);
        java.util.List
<CfgNode> noded = new LinkedList<CfgNode>();
        
        
for (int i=0 ;i<size ;i++ )
        
{
            
int n = i;
            
if (noded.contains(node))
            
{
                n 
= -1;
                
for (CfgNode cfgNode : this.cfgList )
                
{
                    n
++;
                    
if (noded.contains(cfgNode))
                    
{
                        
continue;
                    }

                    node 
= cfgNode;
                    
break;
                }

            }


            noded.add(node);
//为了上边的if判断好做,故在此向noded中添加
            java.util.List<CfgNode> list = node.getSuccessors();
            
int len = list.size();
            
if (len == 0)
            
{
                
continue;
            }


            
int k = 0;
            
            coor 
= this.coorList.get(this.cfgList.indexOf(node));
            startY 
= coor.getY() + 60;
            
for (CfgNode cfgNode : list)
            
{
                startX 
= coor.getX() + k*250;
                k
++;
                
if (this.cfgList.contains(cfgNode))
                
{
                    Coor c 
= (Coor)this.coorList.get(this.cfgList.indexOf(cfgNode));
                    
if (!coor.contains(c))
                    
{
                        coor.addCoor(c);
                    }

                    
continue;
                }

                coor.addCoor(
new Coor(startX, startY));
                
this.cfgList.add(cfgNode);
                
this.coorList.add(new Coor(startX, startY));
            }

            node 
= list.get(0);//这里取到的CfgNode可能已经分析过了,通过上边的if判断可以从cfgList中另外取一个。
        }

    }

    
public void setStartX(int x)
    
{
        
this.startX = x;
    }

    
public void setStartY(int y)
    
{
        
this.startY = y;
    }

    
public int getStartX()
    
{
        
return this.startX;
    }

    
public int getStartY()
    
{
        
return this.startY;
    }

    
public void dump()
    
{
        System.out.println(
"------------------");
        
for (int i=0 ; i<this.cfgList.size(); i++)
        
{
            CfgNode cfgNode 
= this.cfgList.get(i);
            Coor coor 
= this.coorList.get(i);
            System.out.println(cfgNode.toString() 
+ "  "/* + cfgNode.toString()*/ +"  " + coor.getX() + " " + coor.getY() + "  " + coor.getCoors().size());
        }

        System.out.println(
"------------------");
    }

    
    
public void dumpMap()
    
{
        java.util.List
<CfgNode> list = this.cfg.dfPreOrder();
        System.out.println(
"******************");
        
for (CfgNode node : list)
        
{
            System.out.println(
"    " + node.toString() + " " + node.getSuccessors().size());
        }

        System.out.println(
"******************");
    }

    
public static void main(String [] args)
    
{
    
//    new Draw();
    }

    
}


可能这个项目还会做很久,中间会不会有些心得继续放到这个懒得管的空间中来呢,期待着。

< <?php
class Shtml
  {
    var $Templet;
    var $DataSource;
    var $Dir;
 
    var $fileName;
    var $mod;
    var $handle;
 
    function Shtml($fileName="")
    {
      $this->fileName=$fileName;
      $this->mod="wb";
      $this->handle=false;
 
      $this->Templet    = "";
      $this->DataSource  = array();
      $this->Dir      = "";
    }
   
    ///  <描述>
    ///  绑定数据源,参数为一数组。
    ///  </描述>
    function BindData($arr)
    {
      $this->DataSource = $arr;
    }
   
    ///  <描述>
    ///  设置文件存放路径。
    ///  </描述>
    function SetDir($dir)
    {
      $this->Dir = $dir;
    }
    function SetFileName($fileName)
    {
      return $this->fileName=$fileName;
    }
 
    function GetMod()
    {
      return $this->mod;
    }
    function SetMod($mod)
    {
      return $this->mod=$mod;
    }
    function Open()
    {
      if(substr($this->fileName,0,1)=="/")
        $this->fileName = $_SERVER[''DOCUMENT_ROOT''] . $this->fileName;
 

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.111cn.net/mayongzhan - 马永占,myz,mayongzhan

php扩展分为两种.一种是php的扩展,一种是zend扩展.(传说中的,这是programing php里讲的).真的希望能有人发表一些关于zend扩展的东西.这才是真正的核心.
本来是要读下源码的.但是似乎php的源码很多.目前只能扫扫边边角角.如果有机会的话,会去读一下源码的.
其实扩展并不是很难,php已经给好了例子和扩展的工具.使用一下就可以了.
先下php源码,解压
然后到解压目录,ext下 执行./ext_stel --extname=myz
然后到解压目录,执行
./buildconf --force
./configure --with-myz=shared --其他的
make
make install

然后就能看到phpinfo()里面多了个myz了.

这里编译了好几次.好象每次都有新问题.多调试几次一定会成功的."妻儿"不舍

附:php源码包中两个重要的文件内容
README.EXT_SKEL
README.SELF-CONTAINED-EXTENSIONS

README.EXT_SKEL

(NOTE: you may also want to take a look at the pear package
      PECL_Gen, a PHP-only alternative for this script that
    supports way more extension writing tasks and is
    supposed to replace ext_skel completely in the long run ...)

WHAT IT IS

  It''s a tool for automatically creating the basic framework for a PHP module
  and writing C code handling arguments passed to your functions from a simple
  configuration file. See an example at the end of this file.

HOW TO USE IT

  Very simple. First, change to the ext/ directory of the PHP 4 sources. If
  you just need the basic framework and will be writing all the code in your
  functions yourself, you can now do

   ./ext_skel --extname=module_name

  and everything you need is placed in directory module_name.

  [ Note that GNU awk is likely required for this script to work.  Debian
    systems seem to default to using mawk, so you may need to change the
    #! line in skeleton/create_stubs and the cat $proto | awk line in
    ext_skel to use gawk explicitly. ]

  If you don''t need to test the existence of any external header files,
  libraries or functions in them, the module is already almost ready to be
  compiled in PH

<

本文件可以用于自动创建目录下所有JPG图片的缩略图,放到图片目录下运行即可。
缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。



<?php
$config = array();
$config[''path''] = "./";
$config[''t_width''] = 120;
$config[''t_height''] = 98;
$config[''ignore''] = array("",".", SyntaxHighlighter.highlight();
[!--infotagslink--]

相关文章

  • Powershell实现编写和运行脚本

    本文为那些对学习 Windows PowerShell 命令行和脚本编写环境感兴趣的系统管理员提供了资源。也请告诉我们本网站如何才能对您更有用处。...2020-06-30
  • Shell脚本中让进程休眠的方法(sleep用法)

    这篇文章主要介绍了Shell脚本中让进程休眠的方法,本文讲解的就是sleep的用法,可以实现睡觉若干秒、若干分钟、若干小时,需要的朋友可以参考下...2020-07-11
  • MYSQL事务回滚的2个问题分析

    因此,正确的原子操作是真正被执行过的。是物理执行。在当前事务中确实能看到插入的记录。最后只不过删除了。但是AUTO_INCREMENT不会应删除而改变值。1、为什么auto_increament没有回滚?因为innodb的auto_increament的...2014-05-31
  • JavaScript 实现自己的安卓手机自动化工具脚本(推荐)

    这篇文章主要介绍了 JavaScript 实现自己的安卓手机自动化工具脚本,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-05-14
  • 自动设置安卓手机wifi代理的PowerShell脚本

    这篇文章主要介绍了自动设置安卓手机wifi代理的PowerShell脚本,帮助大家进行抓包测试,感兴趣的朋友可以了解下...2020-10-17
  • Mysql索引会失效的几种情况分析

    索引并不是时时都会生效的,比如以下几种情况,将导致索引失效: 1.如果条件中有or,即使其中有条件带索引也不会使用(这也是为什么尽量少用or的原因)  注意:要想使用or,又想让索引生效,只能将or条件中的每个列都加上索引 ...2014-06-07
  • python 爬取京东指定商品评论并进行情感分析

    本文主要讲述了利用Python网络爬虫对指定京东商城中指定商品下的用户评论进行爬取,对数据预处理操作后进行文本情感分析,感兴趣的朋友可以了解下...2021-05-28
  • Underscore源码分析

    Underscore 是一个 JavaScript 工具库,它提供了一整套函数式编程的实用功能,但是没有扩展任何 JavaScript 内置对象。这篇文章主要介绍了underscore源码分析相关知识,感兴趣的朋友一起学习吧...2016-01-02
  • C#中静态的深入理解

    这篇文章详细的介绍了C#中的静态,有需要的朋友可以参考一下...2020-06-25
  • Google会不会取消PR的理由分析

    Google是这样介绍PageRank的:   Google 出类拔萃的地方在于专注开发“完美的搜索引擎”,联合创始人拉里&middot;佩奇将这种搜索引擎定义为可“确解用户...2017-07-06
  • Fatal error: Cannot redeclare class 原因分析与解决办法

    我使用的都是php __autoload状态自动加载类的,今天好好的程序不知道怎么在运行时提示Fatal error: Cannot redeclare class 了,看是重复定义了类,下面我来分析一下解决办...2016-11-25
  • 浅析C#中静态方法和非静态方法的区别

    C#静态方法与非静态方法的区别不仅仅是概念上的,那么他们有什么具体的区别呢?让我们通过本文向大家介绍下C#中静态方法和非静态方法的区别,一起看看吧...2020-06-25
  • PowerShell因为在此系统中禁止执行脚本的解决方法

    今天看到国外的一篇文章可以在cmd中运行95版本的ps1格式的批处理,但经过测试默认情况下powershell支不支持执行脚本需要执行如下操作...2020-06-30
  • 入门shell脚本基础及原理

    弄懂shell程序,源代码,以及python脚本能够向运维开发方向走,shell程序能够管理集群,提高开发的效率,shell是命令解释器,调用系统内核,帮助你对内核的刷新认识...2021-09-06
  • Jmeter如何基于命令行运行jmx脚本

    这篇文章主要介绍了Jmeter如何基于命令行运行jmx脚本,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-22
  • 西部数码空间伪静态配置方法图解

    今天在使用西部数码空间时发现里面有很多定义好的伪静态规则了,下面我来给大家介绍一下在后面主机面板中配置使用伪静态功能吧,希望文章对各位会带来帮助。...2016-10-10
  • shell脚本中用正则表达式匹配IP及Email

    本文我们将会学习一下在shell脚本中如何使用正则表达式,常用的shell正则表达式,当然重点还是如何在shell脚本中用正则表达式匹配IP及Email。 shell也可以使用正则分...2016-11-25
  • Apache在httpd.conf配置文件中设置伪静态(Rewrite)

    .htaccess文件应该被用在内容提供者需要针对特定目录改变服务器的配置而又没有root权限的情况下。如果服务器管理员不愿意频繁修改配置,则可 以允许用户通过.htaccess文件自...2016-01-28
  • 什么是Shell?Shell脚本基础知识详细介绍

    这篇文章主要介绍了什么是Shell?Shell脚本基础知识介绍,本文是一篇Shell脚本入门文章,在本文你可学到什么是Shell、有多少种Shell、一个Shell脚本代码实例,需要的朋友可以参考下...2020-07-11
  • Win7/Windows2003下IIS6.0、IIS7.5的伪静态组件安装和伪静态配置方法

    Win7Windows2003下IIS6.0、IIS7.5的伪静态组件安装和伪静态配置方法,还包括常用的伪静态规则使用方法...2016-01-27