sun.misc.Unsafe
中的函數。此類別中的所有函數本質上使用起來都是不安全的,只能透過反映來存取。sun.misc.Unsafe
類別是用於執行不安全的低階操作,並非設定供開發人員使用。Unsafe
類別只能使用可信任的程式碼來取得,並且通常是透過反映取得,因為它可以用於破壞系統或手動配置堆積記憶體,如果處理不當,就可能會對系統產生有害影響。為了確保不會出現錯誤,仔細檢查和測試與 sun.misc.Unsafe
相關的所有功能十分重要。Value Stack
內容中評估 EL 運算式。允許根據 Value Stack
來評估未驗證的運算式可能會為攻擊者提供修改系統變數或執行任意程式碼的存取權。
OgnlContext ctx = new OgnlContext();
String expression = request.getParameter("input");
Object expr = Ognl.parseExpression(expression);
Object value = Ognl.getValue(expr, ctx, root);
System.out.println("Value: " + value);
(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("calc.exe"))
%{expr}
)。攻擊者在控制第一次評估的結果後,即有可能控制要在第二次 OGNL 評估中評估的運算式,進而插入任意 OGNL 運算式。redirectAction
結果會用於評估其參數兩次。在此案例中,攻擊者可透過提供 redirect
要求參數來控制 actionName
參數中強制 OGNL 運算式的結果。
...
<action name="index" class="com.acme.MyAction">
<result type="redirectAction">
<param name="actionName">${#parameters['redirect']}</param>
<param name="namespace">/foo</param>
</result>
</action>
...
%{#parameters['redirect']}
運算式,該運算式會被當作 OGNL 運算式來進行評估,讓攻擊者能夠評估任意 OGNL 運算式。execute()
之外的方法。!
(驚嘆號) 字元或 method:
字首可用於動作 URL 中,在啟用「動態方法叫用」時叫用動作中的任何公用方法。在 Struts 2 版本 2.3.20
中,叫用先前基於反映之替代方法的機制,已改為使用 OGNL 來代替,這讓攻擊者得以提供惡意 OGNL 運算式來取代替代的方法名稱。debug
要求參數來觸發:console
將會快顯 OGNL 評估主控台,以允許開發人員在伺服器上評估任何任意 OGNL 運算式。command
將允許開發人員使用要求參數 expression
提交任意 OGNL 運算式以進行評估。xml
將參數、上下文、階段作業和值堆疊傾印為 XML 文件。browser
將參數、上下文、階段作業和值堆疊傾印為可瀏覽的 HTML 文件。dest
要求參數解析的 URL。
...
DATA: str_dest TYPE c.
str_dest = request->get_form_field( 'dest' ).
response->redirect( str_dest ).
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所讀取的 URL。
...
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var strDest:String = String(params["dest"]);
host.updateLocation(strDest);
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。PageReference
物件,其包含來自 dest
要求參數的 URL。
public PageReference pageAction() {
...
PageReference ref = ApexPages.currentPage();
Map<String,String> params = ref.getParameters();
return new PageReference(params.get('dest'));
}
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所解析的 URL。
String redirect = Request["dest"];
Response.Redirect(redirect);
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數剖析的 URL。
...
final server = await HttpServer.bind(host, port);
await for (HttpRequest request in server) {
final response = request.response;
final headers = request.headers;
final strDest = headers.value('strDest');
response.headers.contentType = ContentType.text;
response.redirect(Uri.parse(strDest!));
await response.close();
}
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數剖析的 URL。
...
strDest := r.Form.Get("dest")
http.Redirect(w, r, strDest, http.StatusSeeOther)
...
Example 1
中的程式碼會將瀏覽器重新導向至 "http://www.wilyhacker.com"。dest
要求參數所解析的 URL。
<end-state id="redirectView" view="externalRedirect:#{requestParameters.dest}" />
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所讀取的 URL。
...
strDest = form.dest.value;
window.open(strDest,"myresults");
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所解析的 URL。
<%
...
$strDest = $_GET["dest"];
header("Location: " . $strDest);
...
%>
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所解析的 URL。
...
-- Assume QUERY_STRING looks like dest=http://www.wilyhacker.com
dest := SUBSTR(OWA_UTIL.get_cgi_env('QUERY_STRING'), 6);
OWA_UTIL.redirect_url('dest');
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所解析的 URL。
...
strDest = request.field("dest")
redirect(strDest)
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數所解析的 URL:
...
str_dest = req.params['dest']
...
res = Rack::Response.new
...
res.redirect("http://#{dest}")
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。dest
要求參數解析的 URL:
def myAction = Action { implicit request =>
...
request.getQueryString("dest") match {
case Some(location) => Redirect(location)
case None => Ok("No url found!")
}
...
}
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。requestToLoad
設定為指向原始 URL 的「dest」參數 (如果存在的話) 以及指向使用 http://
架構的原始 URL,最後在 WKWebView 內載入此要求:
...
let requestToLoad : String
...
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
...
if let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) {
if let queryItems = urlComponents.queryItems as? [NSURLQueryItem]{
for queryItem in queryItems {
if queryItem.name == "dest" {
if let value = queryItem.value {
request = NSURLRequest(URL:NSURL(string:value))
requestToLoad = request
break
}
}
}
}
if requestToLoad == nil {
urlComponents.scheme = "http"
requestToLoad = NSURLRequest(URL:urlComponents.URL)
}
}
...
}
...
...
let webView : WKWebView
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
webView.loadRequest(appDelegate.requestToLoad)
...
Example 1
中的程式碼將會嘗試在 WKWebView 中要求並載入「http://www.wilyhacker.com」。dest
要求參數所解析的 URL。
...
strDest = Request.Form('dest')
HyperLink.NavigateTo strDest
...
Example 1
中的程式碼會將瀏覽器重新導向至「http://www.wilyhacker.com」。
...
var fs:FileStream = new FileStream();
fs.open(new File("config.properties"), FileMode.READ);
var password:String = fs.readMultiByte(fs.bytesAvailable, File.systemCharset);
URLRequestDefaults.setLoginCredentialsForHost(hostname, usr, password);
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
string password = regKey.GetValue(passKey).ToString());
NetworkCredential netCred =
new NetworkCredential(username,password,domain);
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
RegQueryValueEx(hkey,TEXT(.SQLPWD.),NULL,
NULL,(LPBYTE)password, &size);
rc = SQLConnect(*hdbc, server, SQL_NTS, uid,
SQL_NTS, password, SQL_NTS);
...
password
的值。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。
...
01 RECORD.
05 UID PIC X(10).
05 PASSWORD PIC X(10).
...
EXEC CICS
READ
FILE('CFG')
INTO(RECORD)
RIDFLD(ACCTNO)
...
END-EXEC.
EXEC SQL
CONNECT :UID
IDENTIFIED BY :PASSWORD
AT :MYCONN
USING :MYSERVER
END-EXEC.
...
CFG
的存取權,便能夠讀取密碼的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
<cfquery name = "GetCredentials" dataSource = "master">
SELECT Username, Password
FROM Credentials
WHERE DataSource="users"
</cfquery>
...
<cfquery name = "GetSSNs" dataSource = "users"
username = "#Username#" password = "#Password#">
SELECT SSN
FROM Users
</cfquery>
...
master
表格的存取權,便能夠讀取 Username
和 Password
的值。如果心懷不軌的員工擁有此資訊的存取權,他們可以利用此資訊來進入並破壞系統。
...
file, _ := os.Open("config.json")
decoder := json.NewDecoder(file)
decoder.Decode(&values)
request.SetBasicAuth(values.Username, values.Password)
...
values.Password
的值。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。
...
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
String password = prop.getProperty("password");
DriverManager.getConnection(url, usr, password);
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
String username = credentials[0];
String password = credentials[1];
handler.proceed(username, password);
}
});
...
...
obj = new XMLHttpRequest();
obj.open('GET','/fetchusers.jsp?id='+form.id.value,'true','scott','tiger');
...
plist
檔案讀取密碼,然後使用該密碼解壓縮受密碼保護的檔案。
...
NSDictionary *dict= [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"]];
NSString *password = [dict valueForKey:@"password"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destPath overwrite:TRUE password:password error:&error];
...
...
$props = file('config.properties', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$password = $props[0];
$link = mysql_connect($url, $usr, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
ip_address := OWA_SEC.get_client_ip;
IF ((OWA_SEC.get_user_id = 'scott') AND
(OWA_SEC.get_password = 'tiger') AND
(ip_address(1) = 144) and (ip_address(2) = 25)) THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
...
...
props = os.open('config.properties')
password = props[0]
link = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = password,
db = "test")
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
require 'pg'
...
passwd = ENV['PASSWD']
...
conn = PG::Connection.new(:dbname => "myApp_production", :user => username, :password => passwd, :sslmode => 'require')
PASSWD
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
val prop = new Properties()
prop.load(new FileInputStream("config.properties"))
val password = prop.getProperty("password")
DriverManager.getConnection(url, usr, password)
...
config.properties
的存取權,便能讀取password
的值。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。plist
檔案讀取密碼,然後使用該密碼解壓縮受密碼保護的檔案。
...
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}
if let dict = myDict {
zipArchive.unzipOpenFile(zipPath, password:dict["password"])
}
...
...
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
...
Dim password As String
...
password = GetPrivateProfileString("MyApp", "Password", _
"", value, Len(value), _
App.Path & "\" & "Config.ini")
...
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=scott;Passwd=" & password &";"
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
password = ''.
...
...
URLRequestDefaults.setLoginCredentialsForHost(hostname, "scott", "");
...
Example 1
中的程式碼表示使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
var storedPassword:String = "";
var temp:String;
if ((temp = readPassword()) != null) {
storedPassword = temp;
}
if(storedPassword.equals(userPassword))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 userPassword
而輕易地略過密碼檢查。
...
HttpRequest req = new HttpRequest();
req.setClientCertificate('mycert', '');
...
...
NetworkCredential netCred = new NetworkCredential("scott", "", domain);
...
Example 1
中的程式碼連線成功,表示網路憑證登入「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
string storedPassword = "";
string temp;
if ((temp = ReadPassword(storedPassword)) != null) {
storedPassword = temp;
}
if(storedPassword.Equals(userPassword))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 userPassword
而輕易地略過密碼檢查。
...
rc = SQLConnect(*hdbc, server, SQL_NTS, "scott", SQL_NTS, "", SQL_NTS);
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
char *stored_password = "";
readPassword(stored_password);
if(safe_strcmp(stored_password, user_password))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 user_password
而輕易地略過密碼檢查。
...
<cfquery name = "GetSSNs" dataSource = "users"
username = "scott" password = "">
SELECT SSN
FROM Users
</cfquery>
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
var password = "";
var temp;
if ((temp = readPassword()) != null) {
password = temp;
}
if(password == userPassword()) {
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 userPassword
而輕易地略過密碼檢查。
...
response.SetBasicAuth(usrName, "")
...
...
DriverManager.getConnection(url, "scott", "");
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
String storedPassword = "";
String temp;
if ((temp = readPassword()) != null) {
storedPassword = temp;
}
if(storedPassword.equals(userPassword))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 userPassword
而輕易地略過密碼檢查。
...
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
String username = "";
String password = "";
if (handler.useHttpAuthUsernamePassword()) {
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
username = credentials[0];
password = credentials[1];
}
handler.proceed(username, password);
}
});
...
Example 2
類似,若 useHttpAuthUsernamePassword()
傳回 false
,則攻擊者可以透過提供 Empty Password 來檢視受保護的頁面。
...
obj = new XMLHttpRequest();
obj.open('GET','/fetchusers.jsp?id='+form.id.value,'true','scott','');
...
{
...
"password" : ""
...
}
...
rc = SQLConnect(*hdbc, server, SQL_NTS, "scott", SQL_NTS, "", SQL_NTS);
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
NSString *stored_password = "";
readPassword(stored_password);
if(safe_strcmp(stored_password, user_password)) {
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 user_password
而輕易地略過密碼檢查。
<?php
...
$connection = mysql_connect($host, 'scott', '');
...
?>
DECLARE
password VARCHAR(20);
BEGIN
password := "";
END;
...
db = mysql.connect("localhost","scott","","mydb")
...
...
conn = Mysql.new(database_host, "scott", "", databasename);
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。""
,做為未指定密碼時的預設值。在此案例中,您還需要確認指定引數的數量正確,以確保密碼可傳送到函數。
...
ws.url(url).withAuth("john", "", WSAuthScheme.BASIC)
...
...
let password = ""
let username = "scott"
let con = DBConnect(username, password)
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
var stored_password = ""
readPassword(stored_password)
if(stored_password == user_password) {
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供空白字串給 user_password
而輕易地略過密碼檢查。
...
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=scott;Passwd=;"
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
password = 'tiger'.
...
...
URLRequestDefaults.setLoginCredentialsForHost(hostname, "scott", "tiger");
...
...
HttpRequest req = new HttpRequest();
req.setClientCertificate('mycert', 'tiger');
...
...
NetworkCredential netCred =
new NetworkCredential("scott", "tiger", domain);
...
...
rc = SQLConnect(*hdbc, server, SQL_NTS, "scott",
SQL_NTS, "tiger", SQL_NTS);
...
...
MOVE "scott" TO UID.
MOVE "tiger" TO PASSWORD.
EXEC SQL
CONNECT :UID
IDENTIFIED BY :PASSWORD
AT :MYCONN
USING :MYSERVER
END-EXEC.
...
...
<cfquery name = "GetSSNs" dataSource = "users"
username = "scott" password = "tiger">
SELECT SSN
FROM Users
</cfquery>
...
...
var password = "foobarbaz";
...
javap -c
指令將程式碼分解,而此程式碼包含了所使用密碼的值。此操作的執行結果可能如以下 Example 1
所示:
javap -c ConnMngr.class
22: ldc #36; //String jdbc:mysql://ixne.com/rxsql
24: ldc #38; //String scott
26: ldc #17; //String tiger
password := "letmein"
...
response.SetBasicAuth(usrName, password)
...
DriverManager.getConnection(url, "scott", "tiger");
...
javap -c
指令將程式碼分解,而此程式碼包含了所使用密碼的值。此操作的執行結果可能如以下 Example 1
所示:
javap -c ConnMngr.class
22: ldc #36; //String jdbc:mysql://ixne.com/rxsql
24: ldc #38; //String scott
26: ldc #17; //String tiger
...
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
handler.proceed("guest", "allow");
}
});
...
Example 1
類似,此程式碼能夠成功執行,但任何有程式碼存取權的人都能有密碼存取權。
...
obj = new XMLHttpRequest();
obj.open('GET','/fetchusers.jsp?id='+form.id.value,'true','scott','tiger');
...
...
{
"username":"scott"
"password":"tiger"
}
...
...
DriverManager.getConnection(url, "scott", "tiger")
...
javap -c
指令將程式碼分解,而此程式碼包含了所使用密碼的值。此操作的執行結果可能如以下 Example 1
所示:
javap -c ConnMngr.class
22: ldc #36; //String jdbc:mysql://ixne.com/rxsql
24: ldc #38; //String scott
26: ldc #17; //String tiger
...
webview.webViewClient = object : WebViewClient() {
override fun onReceivedHttpAuthRequest( view: WebView,
handler: HttpAuthHandler, host: String, realm: String
) {
handler.proceed("guest", "allow")
}
}
...
Example 1
類似,此程式碼能夠成功執行,但任何有程式碼存取權的人都能有密碼存取權。
...
rc = SQLConnect(*hdbc, server, SQL_NTS, "scott",
SQL_NTS, "tiger", SQL_NTS);
...
...
$link = mysql_connect($url, 'scott', 'tiger');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
...
DECLARE
password VARCHAR(20);
BEGIN
password := "tiger";
END;
password = "tiger"
...
response.writeln("Password:" + password)
...
Mysql.new(URI(hostname, 'scott', 'tiger', databasename)
...
...
ws.url(url).withAuth("john", "secret", WSAuthScheme.BASIC)
...
javap -c
指令將程式碼分解,而此程式碼包含了所使用密碼的值。此作業的結果可能如下列Example 1
所示:
javap -c MyController.class
24: ldc #38; //String john
26: ldc #17; //String secret
...
let password = "secret"
let username = "scott"
let con = DBConnect(username, password)
...
...
https://user:secretpassword@example.com
...
...
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=scott;Passwd=tiger;"
...
...
credential_settings:
username: scott
password: tiger
...
...
<param name="foo" class="org.jasypt.util.password.BasicPasswordEncoder">
...
</param>
...
import hashlib
def register(request):
password = request.GET['password']
username = request.GET['username']
hash = hashlib.md5(get_random_salt() + ":" + password).hexdigest()
store(username, hash)
...
require 'openssl'
def register(request)
password = request.params['password']
username = request.params['username']
salt = get_random_salt
hash = OpenSSL::Digest.digest("MD5", salt + ":" + password)
store(username, hash)
end
...
Null
密碼會危及安全性。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
var storedPassword:String = null;
var temp:String;
if ((temp = readPassword()) != null) {
storedPassword = temp;
}
if(Utils.verifyPassword(userPassword, storedPassword))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為這可能會讓攻擊者略過密碼驗證,或可能指出資源是由空白密碼所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
string storedPassword = null;
string temp;
if ((temp = ReadPassword(storedPassword)) != null) {
storedPassword = temp;
}
if (Utils.VerifyPassword(storedPassword, userPassword)) {
// Access protected resources
...
}
...
ReadPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
string storedPassword = null;
string temp;
if ((temp = ReadPassword(storedPassword)) != null) {
storedPassword = temp;
}
if(Utils.VerifyPassword(storedPassword, userPassword))
// Access protected resources
...
}
...
ReadPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
char *stored_password = NULL;
readPassword(stored_password);
if(safe_strcmp(stored_password, user_password))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 user_password
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為這可能會讓攻擊者略過密碼驗證,或可能指出資源是由空白密碼所保護。null
給密碼變數是不當的做法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
String storedPassword = null;
String temp;
if ((temp = readPassword()) != null) {
storedPassword = temp;
}
if(Utils.verifyPassword(userPassword, storedPassword))
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。null
,從 Android WebView 儲存區讀取憑證 (若伺服器先前並未拒絕目前要求的憑證),並使用這些資訊設定對檢視受保護頁面的驗證。
...
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
String username = null;
String password = null;
if (handler.useHttpAuthUsernamePassword()) {
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
username = credentials[0];
password = credentials[1];
}
handler.proceed(username, password);
}
});
...
Example 1
類似,若 useHttpAuthUsernamePassword()
傳回 false
,則攻擊者可以透過提供 null
密碼來檢視受保護的頁面。null
密碼絕對不是個好方法。null
初始化:
...
var password=null;
...
{
password=getPassword(user_data);
...
}
...
if(password==null){
// Assumption that the get didn't work
...
}
...
null
給密碼變數,因為這可能會讓攻擊者略過密碼驗證,或可能指出資源未使用密碼保護。null
密碼。
{
...
"password" : null
...
}
null
密碼。Null
密碼會危及安全性。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
NSString *stored_password = NULL;
readPassword(stored_password);
if(safe_strcmp(stored_password, user_password)) {
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 user_password
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
<?php
...
$storedPassword = NULL;
if (($temp = getPassword()) != NULL) {
$storedPassword = $temp;
}
if(strcmp($storedPassword,$userPassword) == 0) {
// Access protected resources
...
}
...
?>
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
。
DECLARE
password VARCHAR(20);
BEGIN
password := null;
END;
null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
storedPassword = NULL;
temp = getPassword()
if (temp is not None) {
storedPassword = temp;
}
if(storedPassword == userPassword) {
// Access protected resources
...
}
...
getPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 userPassword
而輕易地略過密碼檢查。nil
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由空白密碼所保護。nil
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
@storedPassword = nil
temp = readPassword()
storedPassword = temp unless temp.nil?
unless Utils.passwordVerified?(@userPassword, @storedPassword)
...
end
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 @userPassword
而輕易地略過密碼檢查。nil
,做為未指定密碼時的預設值。在此案例中,您還需要確認指定引數的數量正確,以確保密碼可傳送到函數。null
給密碼變數是不當的做法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
ws.url(url).withAuth("john", null, WSAuthScheme.BASIC)
...
null
密碼。Null
密碼會危及安全性。nil
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由空白密碼所保護。null
,嘗試讀取已儲存的密碼值,並與使用者提供的值進行比較。
...
var stored_password = nil
readPassword(stored_password)
if(stored_password == user_password) {
// Access protected resources
...
}
...
readPassword()
因為資料庫錯誤或其他問題而無法擷取儲存的密碼,攻擊者就可藉由提供 null
值給 user_password
而輕易地略過密碼檢查。null
給密碼變數絕對不是個好方法,因為會讓攻擊者略過密碼驗證,或指出資源是由 Empty Password 所保護。null
,並使用該密碼來連線至資料庫。
...
Dim storedPassword As String
Set storedPassword = vbNullString
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=scott;Passwd=" & storedPassword &";"
...
Example 1
中的程式碼連線成功,表示資料庫使用者帳戶「scott」是以 Empty Password 配置,攻擊者可輕易地猜測出此密碼。程式發佈後,需要變更程式碼才可以更新帳戶以使用非 Empty Password。
...
* Default username for FTP connection is "scott"
* Default password for FTP connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
* Default username for database connection is "scott"
* Default password for database connection is "tiger"
...
...
<!-- Default username for database connection is "scott" -->
<!-- Default password for database connection is "tiger" -->
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
-- Default username for database connection is "scott"
-- Default password for database connection is "tiger"
...
...
# Default username for database connection is "scott"
# Default password for database connection is "tiger"
...
...
#Default username for database connection is "scott"
#Default password for database connection is "tiger"
...
...
// Default username for database connection is "scott"
// Default password for database connection is "tiger"
...
...
'Default username for database connection is "scott"
'Default password for database connection is "tiger"
...
response.sendRedirect("j_security_check?j_username="+usr+"&j_password="+pass);
...
var fs:FileStream = new FileStream();
fs.open(new File("config.properties"), FileMode.READ);
var decoder:Base64Decoder = new Base64Decoder();
decoder.decode(fs.readMultiByte(fs.bytesAvailable, File.systemCharset));
var password:String = decoder.toByteArray().toString();
URLRequestDefaults.setLoginCredentialsForHost(hostname, usr, password);
...
config.properties
的存取權,都可讀取 password
的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
string value = regKey.GetValue(passKey).ToString());
byte[] decVal = Convert.FromBase64String(value);
NetworkCredential netCred =
new NetworkCredential(username,decVal.toString(),domain);
...
password
的值。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
RegQueryValueEx(hkey, TEXT(.SQLPWD.), NULL,
NULL, (LPBYTE)password64, &size64);
Base64Decode(password64, size64, (BYTE*)password, &size);
rc = SQLConnect(*hdbc, server, SQL_NTS, uid,
SQL_NTS, password, SQL_NTS);
...
password64
的值,然後輕鬆判斷該值是否使用 base64 編碼。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。
...
01 RECORDX.
05 UID PIC X(10).
05 PASSWORD PIC X(10).
05 LEN PIC S9(4) COMP.
...
EXEC CICS
READ
FILE('CFG')
INTO(RECORDX)
RIDFLD(ACCTNO)
...
END-EXEC.
CALL "g_base64_decode_inplace" using
BY REFERENCE PASSWORD
BY REFERENCE LEN
ON EXCEPTION
DISPLAY "Requires GLib library" END-DISPLAY
END-CALL.
EXEC SQL
CONNECT :UID
IDENTIFIED BY :PASSWORD
END-EXEC.
...
CFG
的存取權,便能夠讀取密碼的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
file, _ := os.Open("config.json")
decoder := json.NewDecoder(file)
decoder.Decode(&values)
password := base64.StdEncoding.DecodeString(values.Password)
request.SetBasicAuth(values.Username, password)
...
config.json
的存取權,都可讀取 password
的值,並可輕易地判定該值是否以 base64 編碼。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。
...
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
String password = Base64.decode(prop.getProperty("password"));
DriverManager.getConnection(url, usr, password);
...
config.properties
的存取權,都可讀取 password
的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
String username = new String(Base64.decode(credentials[0], DEFAULT));
String password = new String(Base64.decode(credentials[1], DEFAULT));
handler.proceed(username, password);
}
});
...
...
obj = new XMLHttpRequest();
obj.open('GET','/fetchusers.jsp?id='+form.id.value,'true','scott','tiger');
...
plist
檔案讀取密碼,然後使用該密碼解壓縮受密碼保護的檔案。
...
NSDictionary *dict= [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"]];
NSString *encoded_password = [dict valueForKey:@"encoded_password"];
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:encoded_password options:0];
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destPath overwrite:TRUE password:decodedString error:&error];
...
Config.plist
的存取權,都可讀取 encoded_password
的值,並可輕易地判定該值是否以 base64 編碼。
...
$props = file('config.properties', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$password = base64_decode($props[0]);
$link = mysql_connect($url, $usr, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
...
config.properties
的存取權,都可讀取 password
的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
props = os.open('config.properties')
password = base64.b64decode(props[0])
link = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = password,
db = "test")
...
config.properties
的存取權,都可讀取 password
的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
require 'pg'
require 'base64'
...
passwd = Base64.decode64(ENV['PASSWD64'])
...
conn = PG::Connection.new(:dbname => "myApp_production", :user => username, :password => passwd, :sslmode => 'require')
PASSWD64
的值,而且輕鬆地判定此值是以 64 位元為基礎進行編碼的。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
...
val prop = new Properties();
prop.load(new FileInputStream("config.properties"));
val password = Base64.decode(prop.getProperty("password"));
DriverManager.getConnection(url, usr, password);
...
config.properties
的存取權,都可讀取password
的值,並可輕易地判定該值是否以 base64 編碼。若不懷好意的員工有此資訊的存取權,則可能使用此資訊來進入並破壞系統。plist
檔案讀取密碼,然後使用該密碼解壓縮受密碼保護的檔案。
...
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}
if let dict = myDict {
let password = base64decode(dict["encoded_password"])
zipArchive.unzipOpenFile(zipPath, password:password])
}
...
Config.plist
的存取權,都可讀取 encoded_password
的值,並可輕易地判定該值是否以 base64 編碼。
...
root:qFio7llfVKk.s:19033:0:99999:7:::
...
...
...
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
...
Dim password As String
...
password = StrConv(DecodeBase64(GetPrivateProfileString("MyApp", "Password", _
"", value, Len(value), _
App.Path & "\" & "Config.ini")), vbUnicode)
...
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=scott;Passwd=" & password &";"
...
Config.ini
的存取權,都可讀取 Password
的值,並可輕易地判定該值是否以 base64 編碼。若心懷不軌的員工擁有此資訊的存取權,則他們可以利用此資訊來進入並破壞系統。
String password=request.getParameter("password");
...
DefaultUser user = (DefaultUser) ESAPI.authenticator().createUser(username, password, password);
...
*Get the report that is to be deleted
r_name = request->get_form_field( 'report_name' ).
CONCATENATE `C:\\users\\reports\\` r_name INTO dsn.
DELETE DATASET dsn.
...
..\\..\\usr\\sap\\DVEBMGS00\\exe\\disp+work.exe
」的檔案名稱,應用程式將刪除關鍵檔案並立即使 SAP 系統當機。
...
PARAMETERS: p_date TYPE string.
*Get the invoice file for the date provided
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'INVOICE'
parameter_1 = p_date
IMPORTING
file_name = v_file
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
OPEN DATASET v_file FOR INPUT IN TEXT MODE.
DO.
READ DATASET v_file INTO v_record.
IF SY-SUBRC NE 0.
EXIT.
ELSE.
WRITE: / v_record.
ENDIF.
ENDDO.
...
..\\..\\usr\\sap\\sys\\profile\\default.pfl
」的字串而非有效日期,應用程式將顯示所有預設的 SAP 應用程式伺服器設定檔參數設定 - 可能會導致更精確的攻擊。../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並寫入「除錯」主控台或記錄檔。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var rName:String = String(params["reportName"]);
var rFile:File = new File("/usr/local/apfr/reports/" + rName);
...
rFile.deleteFile();
.txt
的任意檔案。
var fs:FileStream = new FileStream();
fs.open(new File(String(configStream.readObject())+".txt"), FileMode.READ);
fs.readBytes(arr);
trace(arr);
public class MyController {
...
public PageRerference loadRes() {
PageReference ref = ApexPages.currentPage();
Map<String,String> params = ref.getParameters();
if (params.containsKey('resName')) {
if (params.containsKey('resPath')) {
return PageReference.forResource(params.get('resName'), params.get('resPath'));
}
}
return null;
}
}
..\\..\\Windows\\System32\\krnl386.exe
」的可能性,這會導致應用程式刪除重要的 Windows 系統檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為「.txt」的任意檔案。
String rName = Request.Item("reportName");
...
File.delete("C:\\users\\reports\\" + rName);
sr = new StreamReader(resmngr.GetString("sub")+".txt");
while ((line = sr.ReadLine()) != null) {
Console.WriteLine(line);
}
../../apache/conf/httpd.conf
」的可能性,這會導致應用程式刪除特定組態設定檔案。範例 2:以下程式碼使用來自指令行的輸入,來決定要開啟哪個檔案並回傳給使用者。如果程式需要適當權限才能執行,且惡意使用者能夠建立檔案的軟連結,他們就可以使用程式來讀取系統中任何檔案的開始部分。
char* rName = getenv("reportName");
...
unlink(rName);
ifstream ifs(argv[0]);
string s;
ifs >> s;
cout << s;
...
EXEC CICS
WEB READ
FORMFIELD(FILE)
VALUE(FILENAME)
...
END-EXEC.
EXEC CICS
READ
FILE(FILENAME)
INTO(RECORD)
RIDFLD(ACCTNO)
UPDATE
...
END-EXEC.
...
..\\..\\Windows\\System32\\krnl386.exe
」的可能性,這會導致應用程式刪除重要的 Windows 系統檔案。
<cffile action = "delete"
file = "C:\\users\\reports\\#Form.reportName#">
final server = await HttpServer.bind('localhost', 18081);
server.listen((request) async {
final headers = request.headers;
final path = headers.value('path');
File(path!).delete();
}
Example 1
中,未先驗證 headers.value('path')
即對檔案執行刪除功能。../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自組態設定檔案的輸入,來決定開啟哪個檔案並返回給使用者。如果程式以足夠的權限執行,而且惡意使用者可以變更組態設定檔案,則他們可以使用程式讀取系統上以副檔名
rName := "/usr/local/apfr/reports/" + req.FormValue("fName")
rFile, err := os.OpenFile(rName, os.O_RDWR|os.O_CREATE, 0755)
defer os.Remove(rName);
defer rFile.Close()
...
.txt
結尾的任何檔案。
...
config := ReadConfigFile()
filename := config.fName + ".txt";
data, err := ioutil.ReadFile(filename)
...
fmt.Println(string(data))
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
String rName = request.getParameter("reportName");
File rFile = new File("/usr/local/apfr/reports/" + rName);
...
rFile.delete();
.txt
的任意檔案。
fis = new FileInputStream(cfg.getProperty("sub")+".txt");
amt = fis.read(arr);
out.println(arr);
Example 1
以適用於 Android 平台。
...
String rName = this.getIntent().getExtras().getString("reportName");
File rFile = getBaseContext().getFileStreamPath(rName);
...
rFile.delete();
...
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自本機儲存的輸入,來決定開啟哪個檔案並返回給使用者。如果惡意使用者能夠變更本機儲存的內容,便可以使用程式來讀取系統上副檔名為
...
var reportNameParam = "reportName=";
var reportIndex = document.indexOf(reportNameParam);
if (reportIndex < 0) return;
var rName = document.URL.substring(reportIndex+reportNameParam.length);
window.requestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
fs.root.getFile('/usr/local/apfr/reports/' + rName, {create: false}, function(fileEntry) {
fileEntry.remove(function() {
console.log('File removed.');
}, errorHandler);
}, errorHandler);
}, errorHandler);
.txt
的任何檔案。
...
var filename = localStorage.sub + '.txt';
function oninit(fs) {
fs.root.getFile(filename, {}, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var txtArea = document.createElement('textarea');
txtArea.value = this.result;
document.body.appendChild(txtArea);
};
reader.readAsText(file);
}, errorHandler);
}, errorHandler);
}
window.requestFileSystem(window.TEMPORARY, 1024*1024, oninit, errorHandler);
...
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自組態設定檔案的輸入,來決定開啟哪個檔案並返回給使用者。如果程式以足夠的權限執行,而且惡意使用者可以變更組態設定檔案,則他們可以使用程式讀取系統上以副檔名
val rName: String = request.getParameter("reportName")
val rFile = File("/usr/local/apfr/reports/$rName")
...
rFile.delete()
.txt
結尾的任何檔案。
fis = FileInputStream(cfg.getProperty("sub").toString() + ".txt")
amt = fis.read(arr)
out.println(arr)
Example 1
以適用於 Android 平台。
...
val rName: String = getIntent().getExtras().getString("reportName")
val rFile: File = getBaseContext().getFileStreamPath(rName)
...
rFile.delete()
...
- (NSData*) testFileManager {
NSString *rootfolder = @"/Documents/";
NSString *filePath = [rootfolder stringByAppendingString:[fileName text]];
NSFileManager *fm = [NSFileManager defaultManager];
return [fm contentsAtPath:filePath];
}
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
$rName = $_GET['reportName'];
$rFile = fopen("/usr/local/apfr/reports/" . rName,"a+");
...
unlink($rFile);
.txt
的任意檔案。
...
$filename = $CONFIG_TXT['sub'] . ".txt";
$handle = fopen($filename,"r");
$amt = fread($handle, filesize($filename));
echo $amt;
...
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
rName = req.field('reportName')
rFile = os.open("/usr/local/apfr/reports/" + rName)
...
os.unlink(rFile);
.txt
的任意檔案。
...
filename = CONFIG_TXT['sub'] + ".txt";
handle = os.open(filename)
print handle
...
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
rName = req['reportName']
File.delete("/usr/local/apfr/reports/#{rName}")
.txt
的任意檔案。
...
fis = File.new("#{cfg.getProperty("sub")}.txt")
amt = fis.read
puts amt
../../tomcat/conf/server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
def readFile(reportName: String) = Action { request =>
val rFile = new File("/usr/local/apfr/reports/" + reportName)
...
rFile.delete()
}
.txt
的任意檔案。
val fis = new FileInputStream(cfg.getProperty("sub")+".txt")
val amt = fis.read(arr)
out.println(arr)
func testFileManager() -> NSData {
let filePath : String = "/Documents/\(fileName.text)"
let fm : NSFileManager = NSFileManager.defaultManager()
return fm.contentsAtPath(filePath)
}
..\conf\server.xml
」的可能性,這會導致應用程式刪除本身其中一個組態設定檔案。範例 2:以下程式碼使用來自配置檔案的輸入,來決定要開啟哪個檔案並返回給使用者。如果程式需要適當權限才能執行,且惡意使用者可以變更配置檔案,則他們可以使用程式來讀取系統中結尾副檔名為
Dim rName As String
Dim fso As New FileSystemObject
Dim rFile as File
Set rName = Request.Form("reportName")
Set rFile = fso.GetFile("C:\reports\" & rName)
...
fso.DeleteFile("C:\reports\" & rName)
...
.txt
的任意檔案。
Dim fileName As String
Dim tsContent As String
Dim ts As TextStream
Dim fso As New FileSystemObject
fileName = GetPrivateProfileString("MyApp", "sub", _
"", value, Len(value), _
App.Path & "\" & "Config.ini")
...
Set ts = fso.OpenTextFile(fileName,1)
tsContent = ts.ReadAll
Response.Write tsContent
...
public static void UnzipFile(ZipArchive archive, string destDirectory)
{
foreach (var entry in archive.Entries)
{
string file = entry.FullName;
if (!string.IsNullOrEmpty(file))
{
string destFileName = Path.Combine(destDirectory, file);
entry.ExtractToFile(destFileName, true);
}
}
}
Example 1
中,沒有先驗證 entry.FullName
,就對此項目中的資料執行讀/寫作業。如果 Zip 檔案原本是放置在「C:\TEMP
」目錄中,而 Zip 項目名稱包含「..\
片段」,且應用程式是在所需權限下執行,則會任意覆寫系統檔案。
func Unzip(src string, dest string) ([]string, error) {
var filenames []string
r, err := zip.OpenReader(src)
if err != nil {
return filenames, err
}
defer r.Close()
for _, f := range r.File {
// Store filename/path for returning and using later on
fpath := filepath.Join(dest, f.Name)
filenames = append(filenames, fpath)
if f.FileInfo().IsDir() {
// Make Folder
os.MkdirAll(fpath, os.ModePerm)
continue
}
// Make File
if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
return filenames, err
}
outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return filenames, err
}
rc, err := f.Open()
if err != nil {
return filenames, err
}
_, err = io.Copy(outFile, rc)
// Close the file without defer to close before next iteration of loop
outFile.Close()
rc.Close()
if err != nil {
return filenames, err
}
}
return filenames, nil
}
Example 1
中,沒有先驗證 f.Name
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案原本是放置在 Unix 機器的「/tmp/
」目錄中,Zip 項目為「../etc/hosts
」,並根據必要的權限執行應用程式,將會覆寫系統 hosts
檔案。此舉轉而會允許從機器將流量送到攻擊者所要的任何位置,例如,返回攻擊者的機器。
private static final int BUFSIZE = 512;
private static final int TOOBIG = 0x640000;
...
public final void unzip(String filename) throws IOException {
FileInputStream fis = new FileInputStream(filename);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry zipEntry = null;
int numOfEntries = 0;
long total = 0;
try {
while ((zipEntry = zis.getNextEntry()) != null) {
byte data[] = new byte[BUFSIZE];
int count = 0;
String outFileName = zipEntry.getName();
if (zipEntry.isDirectory()){
new File(outFileName).mkdir(); //create the new directory
continue;
}
FileOutputStream outFile = new FileOutputStream(outFileName);
BufferedOutputStream dest = new BufferedOutputStream(outFile, BUFSIZE);
//read data from Zip, but do not read huge entries
while (total + BUFSIZE <= TOOBIG && (count = zis.read(data, 0, BUFSIZE)) != -1) {
dest.write(data, 0, count);
total += count;
}
...
}
} finally{
zis.close();
}
}
...
Example 1
中,沒有先驗證 zipEntry.getName()
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案原本是放置在 Unix 機器的「/tmp/
」目錄中,Zip 項目為「../etc/hosts
」,並根據必要的權限執行應用程式,將會覆寫系統 hosts
檔案。此舉轉而會允許從機器將流量送到攻擊者所要的任何位置,例如,返回攻擊者的機器。
var unzipper = require('unzipper');
var fs = require('fs');
var untrusted_zip = getZipFromRequest();
fs.createReadStream(zipPath).pipe(unzipper.Extract({ path: 'out' }));
ZZArchive* archive = [ZZArchive archiveWithURL:[NSURL fileURLWithPath: zipPath] error:&error];
for (ZZArchiveEntry* entry in archive.entries) {
NSString *fullPath = [NSString stringWithFormat: @"%@/%@", destPath, [entry fileName]];
[[entry newDataWithError:nil] writeToFile:newFullPath atomically:YES];
}
Example 1
中,沒有先驗證 entry.fileName
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案原本是放置在 iOS 應用程式的「Documents/hot_patches
」目錄中,Zip 項目為「../js/page.js
」,將會覆寫 page.js
檔案。此舉進而會允許攻擊者插入可能會導致執行程式碼的惡意程式碼。
...
$zip = new ZipArchive();
$zip->open("userdefined.zip", ZipArchive::RDONLY);
$zpm = $zip->getNameIndex(0);
$zip->extractTo($zpm);
...
Example 1
中,沒有先驗證 f.Name
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案位於 Unix 機器的「/tmp/
」目錄中,Zip 項目為「../etc/hosts
」,並根據必要的權限執行應用程式,將會覆寫系統 hosts
檔案。此舉會允許從機器將流量送到攻擊者所要的任何位置,例如,返回攻擊者的機器。
import zipfile
import tarfile
def unzip(archive_name):
zf = zipfile.ZipFile(archive_name)
zf.extractall(".")
zf.close()
def untar(archive_name):
tf = tarfile.TarFile(archive_name)
tf.extractall(".")
tf.close()
範例 2:以下範例會從 Zip 檔案解壓縮檔案,然後以不安全的方式將檔案寫入磁碟。
import better.files._
...
val zipPath: File = getUntrustedZip()
val destinationPath = file"out/dest"
zipPath.unzipTo(destination = destinationPath)
import better.files._
...
val zipPath: File = getUntrustedZip()
val destinationPath = file"out/dest"
zipPath.newZipInputStream.mapEntries( (entry : ZipEntry) => {
entry.extractTo(destinationPath, new FileInputStream(entry.getName))
})
Example 2
中,沒有先驗證 entry.getName
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案原本是放置在 Unix 機器的「/tmp/
」目錄中,Zip 項目為「../etc/hosts
」,並根據必要的權限執行應用程式,將會覆寫系統 hosts
檔案。此舉轉而會允許從機器將流量送到攻擊者所要的任何位置,例如,返回攻擊者的機器。
let archive = try ZZArchive.init(url: URL(fileURLWithPath: zipPath))
for entry in archive.entries {
let fullPath = URL(fileURLWithPath: destPath + "/" + entry.fileName)
try entry.newData().write(to: fullPath)
}
Example 1
中,沒有先驗證 entry.fileName
,就對此項目中的資料執行讀/寫功能。如果 Zip 檔案原本是放置在 iOS 應用程式的「Documents/hot_patches
」目錄中,Zip 項目為「../js/page.js
」,將會覆寫 page.js
檔案。此舉進而會允許攻擊者插入可能會導致執行程式碼的惡意程式碼。