常見Web攻擊

2022-04-10 18:16:58 字數 3672 閱讀 9804

1. sql注入的危害 

2. 例項

mysqldb

# 通過在使用者名稱裡面構建乙個sql語句,達到了我們在執行sql語句的時候永遠為真的情況

# username = '~ or 1=1'

username = request.post.get('username')

password = request.post.get('password')

import mysqldb

conn = mysqldb.connect(host='127.0.0.1', user='root', db='mxonline', password='0000')

cursor = conn.cursor()

sql_select = "select * from users_userprofile where email='' and password=''".format(username, password)

result = cursor.execute(sql_select)

for row in cursor.fetchall():

# 查詢到所有使用者

3. 防範

mysqldb

c=db.cursor()

max_price=5

c.execute("""select spam, eggs, sausage from breakfast

where price < %s""", [max_price])

sqlalchemy

from sqlalchemy.orm import sessionmaker

from sqlalchemy import create_engine

from sqlalchemy.orm import scoped_session

from models import student,course,student2course

engine = create_engine(

"mysql+pymysql:",

max_overflow=0, # 超過連線池大小外最多建立的連線

pool_size=5, # 連線池大小

pool_timeout=30, # 池中沒有執行緒最多等待的時間,否則報錯

pool_recycle=-1 # 多久之後對執行緒池中的執行緒進行一次連線的**(重置)

) sessionfactory = sessionmaker(bind=engine)

session = scoped_session(sessionfactory)

cursor = session.execute('insert into users(name) values(:value)', params=)

session.commit()

print(cursor.lastrowid)

from sqlalchemy.sql import text

t = text("select * from test where id= :tid")

conn.execute(t, tid=1).fetchall()

flask-sqlalchemy

conn = db.session.connection()

def index():

rv = conn.execute('select * from test where id = %s', [1])

return jsonify(rv)

pymysql

def fetchall(sql, arg=list(), type=pymysql.cursors.dictcursor):

conn, cursor = connect(type)

cursor.execute(sql, arg)

data = cursor.fetchall()

connect_close(conn, cursor)

return data

1.xss跨站指令碼攻擊(cross site scripting)的危害

2.xss攻擊防範

3. xssf防範**

#

!/usr/bin/env python

#-*- coding:utf-8 -*-

from bs4 import

beautifulsoup

class

xssfilter(object):

__instance =none

def__init__

(self):

#xss白名單

self.valid_tags =

def__new__(cls, *args, **kwargs):

"""單例模式

:param cls:

:param args:

:param kwargs:

:return:

"""if

not cls.__instance

: obj = object.__new__(cls, *args, **kwargs)

cls.

__instance =obj

return cls.__instance

defprocess(self, content):

soup = beautifulsoup(content, '

html.parser')

#遍歷所有html標籤

for tag in soup.find_all(recursive=true):

#判斷標籤名是否在白名單中

if tag.name not

inself.valid_tags:

tag.hidden =true

if tag.name not

in ['

html

', '

body']:

tag.hidden =true

tag.clear()

continue

#當前標籤的所有屬性白名單

attr_rules =self.valid_tags[tag.name]

keys =list(tag.attrs.keys())

for key in

keys:

if key not

inattr_rules:

deltag[key]

return

soup.decode()

if__name__ == '

__main__':

html = """

the dormouse's story

once upon a time there were three little sisters; and their names were

lacie and

tilffffffffffffflie;

and they lived at the bottom of a well.

..."""

obj =xssfilter()

v =obj.process(html)

print(v)

xss.py

1. csrf跨站請求偽造(cross-site request forgery)的危害

2. 防範

常見的 Web 應用攻擊

在 owasp 組織列舉的十大 web 應用安全隱患中,有兩個概率最高的攻擊手段,它們分別是 跨站點指令碼攻擊 cross site scripting 和 注入缺陷 injection flaws 下面將通過舉例來說明這兩種攻擊是如何實施的。1 跨站點指令碼攻擊 首先來看一下跨站點指令碼的利用過程...

Web常見的攻擊手段

type text name name value 當輸入的內容為 alert hello script 最終的效果為 type text name name value alert hello script 這時候就會彈出來hello。這樣的惡作劇還好,如果是獲取使用者賬號密碼的的指令碼呢,那樣的...

常見的web攻擊手段

xss 跨站指令碼攻擊 當使用者在表達輸入一段資料後,提交給服務端進行持久化。如果此使用者輸入的是一段指令碼語言,而服務端 使用者輸入的資料沒有經過轉碼 校驗等就存入了資料庫,在其他頁面需要展示此資料時,就會執行此使用者輸入的語言。簡單來說,js的強大不用我來解釋吧 對使用者輸入的資訊進行轉義,例如...