搜尋
首頁php教程PHP源码PHP静态分析与跨站脚本检测

<script>ec(2);</script>
 最近在看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 ListCoor> coors;
    
public Coor(int x, int y)
    
{
        
this.coors = new LinkedListCoor>();
        
this.x = x;
        
this.y = y;
    }

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

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

    
public ListCoor> 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.ListCfgNode> cfgList;
    
private java.util.ListCoor> coorList;
    
    
/** Creates a new instance of OvalJPanel */
    
public DrawPanel(java.util.ListCfgNode> cfgList, java.util.ListCoor> coorList) 
    
{
        
this.cfgList = cfgList;
        
this.coorList = coorList;
    }

    
//在面板上绘制图形
    public void paintComponent(Graphics g)
    
{
        
        
        
for (int i=0 ;ithis.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 MapCfgNode, Coor> map;
    
private java.util.ListCfgNode> cfgList;
    
private java.util.ListCoor> coorList;
    
private int startX = 50;
    
private int startY = 30;

    
/** Creates a new instance of TabbedJFrame */
    
public Draw(Cfg cfg) {
        
//this.map = new TreeMap();
        this.cfgList = new LinkedListCfgNode>();
        
this.coorList = new LinkedListCoor>();
        
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 LinkedListCfgNode>();
        
        
for (int i=0 ;isize ;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.ListCfgNode> 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 ; ithis.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();
    }

    
}


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

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具