...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
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
具有访问权限的人都能读取密码值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。
...
$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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
props = os.open('config.properties')
password = base64.b64decode(props[0])
link = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = password,
db = "test")
...
config.properties
具有访问权限的人都能读取 password
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。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
的值,并且很容易确定这个值是否经过 64 位基址编码。
...
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
的值,并且很容易确定这个值是否经过 64 位基址编码。任何心怀不轨的雇员可以利用手中掌握的信息访问权限入侵系统。
...
*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:下面的代码使用来自于配置文件的输入来决定打开哪个文件,并写入“Debug”控制台或日志文件。如果程序以足够的权限运行,且恶意用户能够篡改配置文件,那么他们可以通过程序读取系统中以扩展名
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
...
Path.Combine
将多个文件路径作为参数。 连接它们可获得一条完整路径,通常后面跟随该文件的 read()
或 write()
调用。 根据第一个参数还是剩余参数是绝对路径,文档介绍了几种不同情况。 如果第二个或剩余参数为绝对路径,则 Path.Combine()
将返回该绝对路径。 以前的参数将忽略。 这里的含义对于具有类似下面示例代码的应用程序而言非常重要。
// Called with user-controlled data
public static bytes[] getFile(String filename)
{
String imageDir = "\\FILESHARE\images\";
filepath = Path.Combine(imageDir, filename);
return File.ReadAllBytes(filepath);
}
C:\\inetpub\wwwroot\web.config
),攻击者可以控制应用程序返回哪个文件。
...
" Add Binary File to
CALL METHOD lr_abap_zip->add
EXPORTING
name = p_ifile
content = lv_bufferx.
" Read Binary File to
CALL METHOD lr_abap_zip->get
EXPORTING
name = p_ifile
IMPORTING
content = lv_bufferx2.
...
Example 1
中,在对此条目中的数据执行读取/写入函数之前未验证 p_ifile
。如果 ZIP 文件最初放置在基于 Unix 的计算机的 "/tmp/
" 目录中,并且 ZIP 条目为 "../etc/hosts
",而应用程序在必要的权限下运行,则它将覆盖系统的 hosts
文件,从而会使该计算机的流量进入攻击者所需的任何位置,例如返回至攻击者的计算机。
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 条目名称包含“..\
segments”,而应用程序在所需的权限下运行,则它可以随意覆盖系统文件。
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
文件,从而可能会使攻击者能够注入可能导致代码执行的恶意代码。FileIOPermissions
。
...
String permissionsXml = GetPermissionsFromXmlFile();
FileIOPermission perm = new FileIOPermission(PermissionState.None);
perm.FromXml(permissionsXml);
perm.Demand();
...
...
CrytoKeyAuditRule auditRule = new CryptoKeyAuditRule(IdRef, (CryptoKeyRights) input, AuditFlags.Success);
...
input
,则他们可以指定能够记录的操作类型。如果用户可以将此操纵到 CryptoKeyRights.Delete
,则他们也许能够读取加密密钥而不记录它,这样您不会意识到攻击者已盗取您的加密密钥。doExchange()
中很少抛出的异常。
try {
doExchange();
}
catch (RareException e) {
// this can never happen
}
RareException
,程序将继续执行,就像未发生任何异常情况。该程序未记录表明特殊情况的任何证据,这可能会导致以后无法解释该程序的行为。DoExchange()
抛出的罕见异常。
try {
DoExchange();
}
catch (RareException e) {
// this can never happen
}
RareException
异常,程序会继续执行,就像什么都没有发生一样。程序不会记录任何有关这一特殊情况的依据,因而事后再查找这一异常就可能很困难。doExchange()
抛出的罕见异常。
try {
doExchange();
}
catch (RareException e) {
// this can never happen
}
RareException
异常,程序会继续执行,就像什么都没有发生一样。程序不会记录任何有关这一特殊情况的依据,因而事后再查找这一异常就可能很困难。doExchange()
抛出的罕见异常。
try {
doExchange();
}
catch (exception $e) {
// this can never happen
}
RareException
异常,程序会继续执行,就像什么都没有发生一样。程序不会记录任何有关这一特殊情况的依据,因而事后再查找这一异常就可能很困难。open()
抛出的罕见异常。
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except:
# This will never happen
pass
RareException
异常,程序会继续执行,就像什么都没有发生一样。程序不会记录任何有关这一特殊情况的依据,因而事后再查找这一异常就可能很困难。Exception
),可能会混淆那些需要特殊处理的异常,或是捕获了不应在程序中这一点捕获的异常。本质上,捕获范围过大的异常与“.NET 分类定义异常”这一目的是相违背的,随着程序的增加而抛出新异常时,这种做法会十分危险。而新发生的异常类型也不会被注意到。
try {
DoExchange();
}
catch (IOException e) {
logger.Error("DoExchange failed", e);
}
catch (FormatException e) {
logger.Error("DoExchange failed", e);
}
catch (TimeoutException e) {
logger.Error("DoExchange failed", e);
}
try {
DoExchange();
}
catch (Exception e) {
logger.Error("DoExchange failed", e);
}
DoExchange()
,以抛出需要以某种不同的方式处理的新异常类型,则范围过大的 catch 块会阻止编译器指出这一情况(有新的异常抛出)。除此以外,这个新的捕获块还可处理 ApplicationException
和 NullReferenceException
类型的异常,这些异常的发生并不在程序员的意料之内。Exception
),可能会混淆那些需要特殊处理的异常,或是捕获了不应在程序中这一点捕获的异常。本质上,捕获范围过大的异常与“Java 分类定义异常”这一目的是相违背的,随着程序的增加而抛出新异常时,这种做法会十分危险。而新发生的异常类型也不会被注意到。
try {
doExchange();
}
catch (IOException e) {
logger.error("doExchange failed", e);
}
catch (InvocationTargetException e) {
logger.error("doExchange failed", e);
}
catch (SQLException e) {
logger.error("doExchange failed", e);
}
try {
doExchange();
}
catch (Exception e) {
logger.error("doExchange failed", e);
}
doExchange()
,以抛出需要以某种不同的方式处理的新异常类型,则范围过大的 catch 块会阻止编译器指出这一情况(有新的异常抛出)。此外,新 catch 块也将处理那些来自于 RuntimeException
的异常,比如 ClassCastException
和 NullPointerException
,而这些异常的发生是不在程序员的计划之内的。NullReferenceException
并不是一个好方法。NullReferenceException
:NullReferenceException
异常来标记错误状况。NullReferenceException
异常。
try {
MysteryMethod();
}
catch (NullReferenceException npe) {
}
Console.Out
或 Console.Error
而不是专门的日志记录工具,会导致难以监控程序的运行状况。
public class MyClass {
...
Console.WriteLine("hello world");
...
}
Console.WriteLine()
来编写消息以进行标准输出。Console.WriteLine
的使用可能会在转向结构化日志记录系统的过程中导致一个漏洞。os.Stdout
或 os.Stderr
而不是专门的日志记录工具,会导致难以监控程序的运行状况。
...
func foo(){
fmt.Println("Hello World")
}
fmt.Println()
编写进行标准输出的消息。os.Stdout
或 os.Stderr
进行日志记录使用可能会在转向结构化日志记录系统的过程中导致漏洞。System.out
或 System.err
而不是专门的日志记录工具,会导致难以监控程序的运行状况。
public class MyClass
...
System.out.println("hello world");
...
}
System.out.println()
编写进行标准输出的消息。System.out
或 System.err
的使用可能会在转向结构化日志记录系统的过程中导致漏洞。process.stdout
或 process.stderr
而不是专门的日志记录工具,会导致难以监控程序的运行状况。
process.stdin.on('readable', function(){
var s = process.stdin.read();
if (s != null){
process.stdout.write(s);
}
});
process.stdout.write()
编写标准输出的消息。process.stdout
或 process.stderr
的使用可能会在转向结构化日志记录系统的过程中导致漏洞。print
或 println
而不是专门的日志记录工具,会导致难以监控程序的运行状况。
class MyClass {
...
println("hello world")
...
}
}
print
或 println
编写进行标准输出的消息。
sys.stdout.write("hello world")
sys.stdout
或 sys.stderr
的使用可能会在转向结构化日志记录系统的过程中导致漏洞。Kernel.puts
、Kernel.warn
或 Kernel.printf
而不是专门的日志记录工具,会导致难以监控程序的行为。
...
puts "hello world"
...
Kernel.puts
编写进行标准输出的消息。Kernel.puts
、Kernel.warn
或 Kernel.printf
的使用可能表示转向结构化日志记录系统过程中的一时疏忽。Logger
类,但是将信息记录到系统输出流:
require 'logger'
...
logger = Logger.new($stdout)
logger.info("hello world")
...
...
var file:File = new File(directoryName + "\\" + fileName);
...
...
FileStream f = File.Create(directoryName + "\\" + fileName);
...
...
File file = new File(directoryName + "\\" + fileName);
...
...
os.open(directoryName + "\\" + fileName);
...
...
uid = 'scott'.
password = 'tiger'.
WRITE: / 'Default username for FTP connection is: ', uid.
WRITE: / 'Default password for FTP connection is: ', password.
...
pass = getPassword();
...
trace(id+":"+pass+":"+type+":"+tstamp);
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
...
ResetPasswordResult passRes = System.resetPassword(id1, true);
System.Debug('New password: '+passRes.getPassword());
...
pass = GetPassword();
...
dbmsLog.WriteLine(id+":"+pass+":"+type+":"+tstamp);
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。get_password()
函数可以从存储的其他值中返回一个由用户提供的、与该用户帐户相关的明文密码。
pass = get_password();
...
fprintf(dbms_log, "%d:%s:%s:%s", id, pass, type, tstamp);
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储所有数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
...
MOVE "scott" TO UID.
MOVE "tiger" TO PASSWORD.
DISPLAY "Default username for database connection is: ", UID.
DISPLAY "Default password for database connection is: ", PASSWORD.
...
Session.pword
变量还包含与该帐户相关的明文密码。
<cflog file="app_log" application="No" Thread="No"
text="#Session.uname#:#Session.pword#:#type#:#Now()#">
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
var pass = getPassword();
...
dbmsLog.println(id+":"+pass+":"+type+":"+tstamp);
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。GetPassword()
函数的返回值,该函数会返回与该帐户关联且由用户提供的明文密码。
pass = GetPassword();
...
if err != nil {
log.Printf('%s: %s %s %s', id, pass, type, tsstamp)
}
Example 1
中的代码会将明文密码记录到应用程序的事件日志中。虽然许多开发人员认为事件日志是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
pass = getPassword();
...
dbmsLog.println(id+":"+pass+":"+type+":"+tstamp);
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
...
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];
Intent i = new Intent();
i.setAction("SEND_CREDENTIALS");
i.putExtra("username", username);
i.putExtra("password", password);
view.getContext().sendBroadcast(i);
}
});
...
SEND_CREDENTIALS
收听的注册接收者都将收到消息。即使权限限制接收者人数,广播也不会受到保护;既然这样,我们也不建议将权限作为修复方式使用。
localStorage.setItem('password', password);
pass = getPassword()
...
dbmsLog.println("$id:$pass:$type:$tstamp")
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
...
webview.webViewClient = object : WebViewClient() {
override fun onReceivedHttpAuthRequest(view: WebView,
handler: HttpAuthHandler, host: String, realm: String
) {
val credentials = view.getHttpAuthUsernamePassword(host, realm)
val username = credentials!![0]
val password = credentials[1]
val i = Intent()
i.action = "SEND_CREDENTIALS"
i.putExtra("username", username)
i.putExtra("password", password)
view.context.sendBroadcast(i)
}
}
...
SEND_CREDENTIALS
收听的注册接收者都将收到消息。即使权限限制接收者人数,广播也不会受到保护;既然这样,我们也不建议将权限作为修复方式使用。
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"dLatitude : %@", latitude);
NSLog(@"dLongitude : %@",longitude);
NSString *urlWithParams = [NSString stringWithFormat:TOKEN_URL, latitude, longitude];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlWithParams]];
[request setHTTPMethod:@"GET"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Add password to user defaults
[defaults setObject:@"Super Secret" forKey:@"passwd"];
[defaults synchronize];
getPassword()
函数的返回值,该函数会返回与该帐户关联且由用户提供的明文密码。
<?php
$pass = getPassword();
trigger_error($id . ":" . $pass . ":" . $type . ":" . $tstamp);
?>
Example 1
中的代码会将明文密码记录到应用程序的事件日志中。虽然许多开发人员认为事件日志是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。OWA_SEC.get_password()
函数会返回一个与用户帐户相关并且由用户提供的明文密码,这个密码将输出给 HTTP 响应。
...
HTP.htmlOpen;
HTP.headOpen;
HTP.title (.Account Information.);
HTP.headClose;
HTP.bodyOpen;
HTP.br;
HTP.print('User ID: ' ||
OWA_SEC.get_user_id || '');
HTP.print('User Password: ' ||
OWA_SEC.get_password || '');
HTP.br;
HTP.bodyClose;
HTP.htmlClose;
...
getPassword()
函数的返回值,该函数会返回与该帐户关联且由用户提供的明文密码。
pass = getPassword();
logger.warning('%s: %s %s %s', id, pass, type, tsstamp)
Example 1
中的代码会将明文密码记录到应用程序的事件日志中。虽然许多开发人员认为事件日志是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。get_password()
函数可以返回一个由用户提供的、与用户帐号相关的明文密码。
pass = get_password()
...
dbms_logger.warn("#{id}:#{pass}:#{type}:#{tstamp}")
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
val pass = getPassword()
...
dbmsLog.println(id+":"+pass+":"+type+":"+tstamp)
Example 1
中的代码会将明文密码记录到文件系统中。虽然许多开发人员认为文件系统是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
import CoreLocation
...
var locationManager : CLLocationManager!
var seenError : Bool = false
var locationFixAchieved : Bool = false
var locationStatus : NSString = "Not Started"
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.locationServicesEnabled
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
...
if let location: CLLocation! = locationManager.location {
var coordinate : CLLocationCoordinate2D = location.coordinate
let latitude = NSString(format:@"%f", coordinate.latitude)
let longitude = NSString(format:@"%f", coordinate.longitude)
NSLog("dLatitude : %@", latitude)
NSLog("dLongitude : %@",longitude)
let urlString : String = "http://myserver.com/?lat=\(latitude)&lon=\(longitude)"
let url : NSURL = NSURL(string:urlString)
let request : NSURLRequest = NSURLRequest(URL:url)
var err : NSError?
var response : NSURLResponse?
var data : NSData = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error:&err)
} else {
println("no location...")
}
let defaults : NSUserDefaults = NSUserDefaults.standardUserDefaults()
// Add password to user defaults
defaults.setObject("Super Secret" forKey:"passwd")
defaults.synchronize()
getPassword
函数可以从存储的其他值中返回一个由用户提供的、与该用户帐户相关的明文密码。
pass = getPassword
...
App.EventLog id & ":" & pass & ":" & type & ":" &tstamp, 4
...
Example 1
中的代码会将明文密码记录到应用程序的事件日志中。虽然许多开发人员认为事件日志是存储数据的安全位置,但这不是绝对的,特别是涉及到隐私问题时。
...
HKHealthStore healthStore = new HKHealthStore();
HKBloodTypeObject blood = healthStore.GetBloodType(null);
NSLog("%@", blood.BloodType);
var urlWithParams = String.format(TOKEN_URL, block.BloodType);
var responseString = await client.GetStringAsync(urlWithParams);
...
NSLog
函数所处的等级更低,开发人员可借助前者创建能够读取设备上所有日志的应用程序,即便他们并不拥有其他应用程序也是如此。
...
HKHealthStore healthStore = new HKHealthStore();
HKBloodTypeObject blood = healthStore.GetBloodType(null);
// Add blood type to user defaults
NSUserDefaults.StandardUserDefaults.SetString(blood.BloodType, "bloodType");
...
...
HKHealthStore *healthStore = [[HKHealthStore alloc] init];
HKBloodTypeObject *blood = [healthStore bloodTypeWithError:nil];
NSLog(@"%@", [blood bloodType]);
NSString *urlWithParams = [NSString stringWithFormat:TOKEN_URL, [blood bloodType]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlWithParams]];
[request setHTTPMethod:@"GET"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
...
NSLog
函数位于更底层的位置,开发者可借助前者创建能够读取设备上所有日志的应用程序,即便他们并不拥有其他应用程序。
...
HKHealthStore *healthStore = [[HKHealthStore alloc] init];
HKBloodTypeObject *blood = [healthStore bloodTypeWithError:nil];
// Add blood type to user defaults
[defaults setObject:[blood bloodType] forKey:@"bloodType"];
[defaults synchronize];
...
...
let healthStore = HKHealthStore()
let blood = try healthStore.bloodType()
print(blood.bloodType)
let urlString : String = "http://myserver.com/?data=\(blood.bloodType)"
let url : NSURL = NSURL(string:urlString)
let request : NSURLRequest = NSURLRequest(URL:url)
var err : NSError?
var response : NSURLResponse?
var data : NSData = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error:&err)
...
NSLog
函数位于更底层的位置,开发者可借助前者创建能够读取设备上所有日志的应用程序,即便他们并不拥有其他应用程序。
...
let healthStore = HKHealthStore()
let blood = try healthStore.bloodType()
print(blood.bloodType)
// Add blood type to user defaults
defaults.setObject("BloodType" forKey:blood.bloodType)
defaults.synchronize()
...
String
对象中。
public static String getPassword() {
String inputPassword = "";
ConsoleKeyInfo nextKey = Console.ReadKey(true);
while (nextKey.Key != Console.ReadKey(true)) {
inputPassword.AppendChar(nextKey.KeyChar);
Console.Write("*");
nextKey = Console.ReadKey(true);
}
return inputPassword;
}
String
是一个不可改变的对象,所以无法使内容失效,这意味着在进行垃圾回收之前能够检查堆的任何人都可以获得敏感数据。String
对象中使系统无法从内存中可靠地清除数据。String
存储敏感数据,因为 String
对象不可改变,只有 JVM 垃圾收集器才能从内存中删除 String
的值,只能由 JVM 垃圾收集器完成。由于除非 JVM 内存不足,否则不需要运行垃圾收集器,因此无法保证垃圾收集何时发生。如果应用程序崩溃,则应用程序的内存转储可能会泄露敏感数据。String
。
private JPasswordField pf;
...
final char[] password = pf.getPassword();
...
String passwordAsString = new String(password);
String
对象中使系统无法从内存中可靠地清除数据。String
用于存储敏感数据,但是因为 String
对象不可改变,所以为其指定新值将创建新的String
并为所指定对象分配新对象的引用。原始值将保留在内存中,直到ARC
(自动引用计数)取消分配对象并释放其内存。Swift 在对象的生命周期方面不作保证,其在最近的周边作用域结束时完成。如果攻击者在取消分配对象之前转储内存内容,则可以读取内容。String
在内存中存储密码。
let password = passwordTextField.text!
// use the password
SensitiveXMLData
生成敏感财务信息图表的 DataVisualization
控件实例化:
<asp:Chart ID="Chart1" runat="server" ImageLocation="~/Temporary/Graph"
ImageType="Jpeg" DataSourceID="SensitiveXMLData" ImageStorageMode="UseImageLocation">
<series>
.
.
.
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
Example 1
中的代码会指示 Chart
控件生成柱状图的 JPEG 图像,并将其写入临时目录 ~/Temporary/Graph
中。在该控件将此图像写入磁盘后,用户浏览器随后会对该文件发起一次请求,并将其显示给用户。该图像未安全写入磁盘。此外,该代码会假定底层基础架构会保护该文件,使其免受其他用户未经授权的访问。DataType
指定为密码,这表示在显示时,系统会默认显示该属性:
public class User
{
[Required]
public int ID { get; set; }
public string Title { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime DateOfEmployment { get; set; }
[DataType(DataType.Currency)]
public decimal Salary { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
...
}
Example 1
中的 Password
属性未指定 [DataType(DataType.Password)]
属性,因此默认情况下在 UI 中显示不会隐藏它。TextField
小组件在用户在输入提示符处输入密码时不会对用户密码进行模糊处理:
class SelectionContainerDisabledExampleApp extends StatelessWidget {
const SelectionContainerDisabledExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
hintText: "Please enter your password",
),
),
],
),
),
),
);
}
}
Example 1
中的 TextField
小组件是在 obscureText
属性设置为 true
的情况下进行实例化的,因此,当用户在“请输入您的密码:”提示符处输入密码时,该密码不会进行模糊显示。PasswordCallback pc = new PasswordCallback("Please enter your password: ", true);
Example 1
中的 pc
是在其第二个参数 onEcho
设置为 true
的情况下进行实例化的,因此,当用户在“请输入您的密码:”提示下输入密码时,该密码不会进行模糊显示。
ViewController.h:
...
@property (nonatomic, retain) IBOutlet UITextField *passwordField;
...
ViewController.m:
...
NSString *password = _passwordField.text;
...
Example 1
中的 passwordField
未将其 secureTextEntry
属性设置为 true
,因此当用户向文本字段中键入密码时,其密码不会进行模糊显示。
...
@IBOutlet weak var passwordField: UITextField!
...
let password = passwordField.text
...
Example 1
中的 passwordField
未将其 secureTextEntry
属性设置为 true
,因此当用户向文本字段中键入密码时,其密码不会进行模糊显示。
...
tid = request->get_form_field( 'tid' ).
CALL TRANSACTION tid USING bdcdata MODE 'N'
MESSAGES INTO messtab.
...
APPHOME
,然后根据指定目录的相对路径加载本地库。
...
string lib = ConfigurationManager.AppSettings["APPHOME"];
Environment.ExitCode = AppDomain.CurrentDomain.ExecuteAssembly(lib);
...
APPHOME
以指向包含恶意版本 LIBNAME
的不同路径,从而使用更高的应用程序权限来执行任意代码。由于程序不会验证从环境中读取的值,因此如果攻击者能够控制系统属性 APPHOME
的值,他们就能欺骗应用程序去运行恶意代码,从而控制系统。
...
RegQueryValueEx(hkey, "APPHOME",
0, 0, (BYTE*)home, &size);
char* lib=(char*)malloc(strlen(home)+strlen(INITLIB));
if (lib) {
strcpy(lib,home);
strcat(lib,INITCMD);
LoadLibrary(lib);
}
...
INITLIB
恶意版本的其他路径,进而允许攻击者加载一个任意库,以提高的应用程序权限去执行库中的任意代码。因为程序不会校验从环境中读取的值,如果攻击者能够控制 APPHOME
的值,就能欺骗应用程序去运行恶意的代码。liberty.dll
的库,该库通常可在一个标准的系统目录中找到。
LoadLibrary("liberty.dll");
liberty.dll
的绝对路径。在搜索顺序上,如果攻击者将一个名为 liberty.dll
的恶意库放在原本想要的库的前面,并且攻击者能够让程序在他们的环境(而不是 web 服务器环境)中运行,那么应用程序就会加载该恶意库,而不是原本想要的可信赖的库。由于这种类型的应用程序会以提高了的权限运行,因此攻击者的 liberty.dll
中的内容也将以提高的权限运行,这可能会使攻击者完全控制系统。LoadLibrary()
所使用的搜索顺序造成的。如果当前目录比系统目录先搜索到,就像现在大多数最新的 Windows 版本,那么如果攻击者可在本地执行程序,这种类型的攻击就会变得十分简单。搜索顺序取决于操作系统的版本,在比较新的操作系统中,这一顺序由注册表主键控制:
HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode
LoadLibrary()
按以下方式运行:SafeDllSearchMode
为 1,搜索顺序如下所示:PATH
环境变量中列出来的目录。SafeDllSearchMode
为 0,搜索顺序如下所示:PATH
环境变量中列出来的目录。
...
ACCEPT PROGNAME.
EXEC CICS
LINK PROGRAM(PROGNAME)
COMMAREA(COMA)
LENGTH(LENA)
DATALENGTH(LENI)
SYSID('CONX')
END-EXEC.
...
APPHOME
来确定系统的安装目录,然后用基于指定目录的相对路径加载本地库。
...
String home = System.getProperty("APPHOME");
String lib = home + LIBNAME;
java.lang.Runtime.getRuntime().load(lib);
...
APPHOME
,指向一个包含恶意版本 LIBNAME
的不同路径,从而使用较高的应用程序权限去执行任意代码。由于程序不会验证从环境中读取的值,所以如果攻击者能够控制系统属性 APPHOME
的值,他们就能欺骗应用程序去运行恶意代码从而取得系统控制权。 System.loadLibrary()
从名为 library.dll
的本地库加载代码,它通常可以在标准的系统目录中找到。
...
System.loadLibrary("library.dll");
...
System.loadLibrary()
只会接受库的名称,而不接受库的路径。根据 Java 1.4.2 API 文档,这个函数会进行如下操作 [1]:library.dll
放在高于应用程序需要加载的文件的位置,那么应用程序就会加载该恶意代码,而不会选择加载最初需要的文件。由于应用程序的这一特性,它会以较高的权限运行,这就意味着攻击者的 library.dll
内容将以较高的权限运行,从而可能导致攻击者完全控制整个系统。Express
当前未记录的“功能”动态加载库文件。然后,Node.js
将继续在其正则库加载路径中搜索包含此库的文件或目录[1]。
var express = require('express');
var app = express();
app.get('/', function(req, res, next) {
res.render('tutorial/' + req.params.page);
});
Express
中,传递到 Response.render()
的页面将加载先前未知的扩展库。这对于“foo.pug”等输入来说通常没有问题,因为这意味着加载 pug
库,该库是广为人知的模板引擎。但是,如果攻击者可以控制页面并进而控制扩展,那么他们便可以选择加载 Node.js
模块加载路径内的任何库。因为程序不会验证从 URL 参数接收的信息,所以攻击者可能会欺骗应用程序,去执行恶意代码并取得对系统的控制。APPHOME
来确定系统的安装目录,然后用基于指定目录的相对路径加载本地库。
...
$home = getenv("APPHOME");
$lib = $home + $LIBNAME;
dl($lib);
...
APPHOME
,指向一个包含恶意版本 LIBNAME
的不同路径,从而使用较高的应用程序权限去执行任意代码。由于程序不会验证从环境中读取的值,所以如果攻击者能够控制系统属性 APPHOME
的值,他们就能欺骗应用程序去运行恶意代码从而取得系统控制权。dl()
来从名为 sockets.dll
的库加载代码,此库可从多个位置加载,具体取决于您的安装和配置。
...
dl("sockets");
...
dl()
只会接受库的名称,而不接受库的路径。sockets.dll
放在高于应用程序需要加载的文件的位置,那么应用程序就会加载该恶意代码,而不会选择加载最初需要的文件。由于应用程序的这一特性,它会以较高的权限运行,这就意味着攻击者的 sockets.dll
内容将以较高的权限运行,从而可能导致攻击者完全控制整个系统。Kernel.system()
来运行称为 program.exe
的可执行文件,通常在标准系统目录中可找到该可执行文件。
...
system("program.exe")
...
Kernel.system()
通过 shell 执行程序。如果攻击者可以操纵 RUBYSHELL
或 COMSPEC
环境变量,这两个环境变量就能够指向恶意的可执行文件,通过为 Kernel.system()
指定的命令将会调用该可执行文件。由于应用程序自身的特性,它需要特定的权限执行系统操作,这意味着攻击者会利用这些权限执行自己的 program.exe
,从而可能导致攻击者完全控制这个系统。Kernel.system()
调用之前未能清理其环境。如果攻击者能够篡改 $PATH
变量,使其指向一个名为 program.exe
的恶意二进制代码,然后在指定环境中运行应用程序,那么应用程序就会加载该恶意二进制代码,并以此替代原本期望的代码。由于应用程序自身的特性,它需要特定的权限执行系统操作,这意味着攻击者会利用这些权限执行自己的 program.exe
,从而可能导致攻击者完全控制这个系统。Windows.Storage.ApplicationData
类的 RoamingFolder
或 RoamingSettings
属性。RoamingFolder
和 RoamingSettings
属性可从漫游应用程序数据存储器中获取一个容器,然后可以使用此容器在两台以上的设备之间共享数据。如果写入和读取漫游应用程序数据存储器中存储的对象,开发人员会增加遭受危害的风险。通过此漫游应用程序数据存储器共享这些对象的数据、应用程序和系统的机密性、完整性和可用性都将受到影响。null
的指针是否为 null
之前间接引用该指针,则会发生 check-after-dereference 错误。如果程序明确检查过 null
,并确定该指针为 null
,但仍继续间接引用该指针,则会出现 dereference-after-check 错误。此类错误通常是由于错别字或程序员疏忽造成的。如果程序明确将指针设置为 null
,但稍后却间接引用该指针,则将出现 dereference-after-store 错误。此错误通常是因为程序员在声明变量时将该变量初始化为 null
所致。foo
为 null
,然后错误地对其进行间接引用。如果在 if
语句中检查 foo
时其为 null
,则会发生 null
间接引用,从而导致 null 指针异常。示例 2:在下列代码中,程序员假设变量
if (foo is null) {
foo.SetBar(val);
...
}
foo
不是 null
,并通过间接引用该对象来确认此假设。但是,程序员稍后通过检查 foo
是否为 null
发现事实与该假设相反。如果在 if
指令中检查时发现 foo
可能是 null
,则在间接引用它时可能也为 null
,并可能引起 null 指针异常。间接引用不安全,或者无需后续检查。示例 3:在下列代码中,程序员会将变量
foo.SetBar(val);
...
if (foo is not null) {
...
}
foo
明确设置为 null
。之后,程序员会间接引用 foo
,而未检查对象是否为 null
值。
Foo foo = null;
...
foo.SetBar(val);
...
}
null
的指针是否为 null
之前间接引用该指针,则会发生 check-after-dereference 错误。如果程序明确检查过 null
,并确定该指针为 null
,但仍继续间接引用该指针,则会出现 dereference-after-check 错误。此类错误通常是由于错别字或程序员疏忽造成的。如果程序明确将指针设置为 null
,但稍后却间接引用该指针,则将出现 dereference-after-store 错误。此错误通常是因为程序员在声明变量时将该变量初始化为 null
所致。ptr
不是 NULL
。当程序员间接引用该指针时,这个假设就会清晰的体现出来。当程序员检查 ptr
是否为 NULL
时,就会与该假设发生矛盾。当在 if
语句中检查时,如果 ptr
可以为 NULL
,则在其间接引用时也将为 NULL
,并引起 segmentation fault。示例 2:在下列代码中,程序员会确认变量
ptr->field = val;
...
if (ptr != NULL) {
...
}
ptr
为 NULL
,然后错误地对其进行间接引用。如果在 if
语句中检查 ptr
时其为 NULL
,则会发生 null
dereference,从而导致分段故障。示例 3:在下列代码中,程序员忘记了字符串
if (ptr == null) {
ptr->field = val;
...
}
'\0'
实际上为 0 还是 NULL
,从而间接引用 null 指针并引发分段故障。示例 4:在下列代码中,程序员会将变量
if (ptr == '\0') {
*ptr = val;
...
}
ptr
明确设置为 NULL
。之后,程序员会间接引用 ptr
,而未检查对象是否为 null
值。
*ptr = NULL;
...
ptr->field = val;
...
}
null
,并确定该指针为 null
,但仍继续间接引用该对象,则会出现 dereference-after-check 错误。此类错误通常是由于错别字或程序员疏忽造成的。foo
为 null
,然后错误地对其进行间接引用。如果在 if
语句中检查 foo
时其为 null
,则会发生 null
dereference,从而导致 null 指针异常。
if (foo == null) {
foo.setBar(val);
...
}