...
* 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
...
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 項目名稱包含「..\
片段」,且應用程式是在所需權限下執行,則會任意覆寫系統檔案。
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
檔案。此舉進而會允許攻擊者插入可能會導致執行程式碼的惡意程式碼。
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
動作收聽用意,即可接收該訊息。這一廣播並未受到權限的保護而限制接收者數量,但即使受到該保護,我們也不建議使用權限做為修正。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
執行此作業,那麼他們可能會在不受記錄的情況下讀取加密金鑰,而您也覺察不到攻擊者已經竊取了您的加密金鑰。allow_url_fopen
選項,便可使用 HTTP 或 FTP URL 在遠端檔案上執行接受檔案名稱的 PHP 函數。該選項是在 PHP 4.0.4 中增加的,在預設情況下是開啟的,因為它可能會讓攻擊者將惡意內容引入至應用程式中。最理想的情況是,攻擊者改變遠端檔案以引入惡意的內容,因此對遠端檔案進行操作使得應用程式易受攻擊。最差的情況是,攻擊者控制執行應用程式的 URL,則他們可以將 URL 提供至遠端伺服器,將任意的惡意內容插入至應用程式。 $file
的值由要求參數控制,所以攻擊者可違反程式設計師的假設,提供 URL 給遠端檔案。
<?php
$file = fopen ($_GET["file"], "r");
if (!$file) {
// handle errors
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
// operate on file content
}
fclose($file);
?>
allow_url_include
選項,會導致用於指定在目前頁面包含某個檔案的 PHP 函數 (例如include()
和 require()
) 接受指向遠端檔案的 HTTP 或 FTP URL。該選是在 PHP 5.2.0 中增加的,且預設情況下為停用,因為它可能會讓攻擊者將惡意內容引入至應用程式中。最理想的情況是,攻擊者改變遠端檔案以引入惡意的內容,因此包含遠端檔案會使應用程式易受攻擊。最糟糕的情況是,攻擊者控制應用程序用來指定要包含的遠端檔案的 URL,則他們可以將 URL 提供至遠端伺服器,將任意的惡意內容插入至應用程式。cgi.force_redirect
(該選項在預設情況下為啟用),則擁有/cgi-bin/php 存取權的攻擊者可以使用 PHP 解譯器的權限來存取任意的 Web 文件,便可略過任何由伺服器所執行的 access control 檢查。dl
的動態載入可用於規避 open_basedir
限制。enable_dl
組態允許動態載入程式庫。這些可能潛在允許攻擊者規避使用 open_basedir 組態設定的限制,並且潛在允許存取系統上的任何檔案。enable_dl
可能更便於攻擊者利用其他弱點。file_uploads
選項,會讓 PHP 使用者上傳任意的檔案到伺服器中。允許使用者上傳檔案這個功能本身並不代表一種安全性弱點。不過,這個功能可能導致許多的攻擊行為,因為它提供途徑給惡意的使用者將資料引入伺服器環境。
<?php
$udir = 'upload/'; // Relative path under Web root
$ufile = $udir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $ufile)) {
echo "Valid upload received\n";
} else {
echo "Invalid upload rejected\n";
} ?>
open_basedir
組態選項,該選項會試圖阻止 PHP 程式對 php.ini 中所指定的目錄結構以外的檔案執行操作。如果沒有使用 open_basedir
選項指定任何目錄,則在 PHP 下執行的程式將被授予擁有本地 file system 上所有檔案的完整存取權,這會使攻擊者可讀取、寫入或建立他們原本不該擁有存取權的檔案。open_basedir
指定限制的目錄集,可能會讓攻擊者更容易發動其他盜取攻擊。open_basedir
選項可保證系統的安全性,但其執行方式卻受到 race condition 的不利影響,這可能會讓攻擊者在某些情況下略過該選項所定義的限制[2]。PHP 執行存取權限檢查和開啟檔案間,會存在 time-of-check、time-of-use (TOCTOU) race condition。與其他語言中 file system 的 race condition 相同,此種情況會讓攻擊者將指向透過 access control 檢查的 symlink 替換成另一個原來不能通過測試的檔案,以取得受保護檔案的存取權。