以下文章向您展示瞭如何在 AWS Elastic Beanstalk 中運行 dotnet 應用程序,然後使用 AcuSensor 對該應用程式運行互動式應用程式安全測試 (IAST) 掃描。
在 Acunetix 中建立您的目標
對於此示範,我們假設您的目標的 URL 是 http://eb.acunetixexample.com。使用您的 URL 創建目標,啟用 AcuSensor,下載 AcuSensor agent dotnet-acusensor.zip,並保存此文件以備後用。
使用 Visual Studio 建立您的網頁應用程式
- 在選單中依序選擇 File -> New -> Project menu option
- 在 Create a new project 窗口中,搜索 web application ,選擇 ASP.NET Web Application (.NET Framework),然後點擊 Next 按鈕
- 設置您的項目名稱(在此範例中我們使用 axexample-dotnet)並點擊 Create 按鈕
- 在 Create a new ASP.NET Web Application 視窗中,選擇 Empty template後並取消選取 Configure for HTTPS,然後點擊 Create 按鈕
- 對著 axexample-dotnet 項目名稱點擊右鍵並選擇 Add -> HTML Page 選單
- 將 Item name 欄位設置為 index,然後點擊 OK 按鈕
- 編輯您的 index.html 文件,如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Test dotNET Site Example for AWS Elastic Beanstalk</h1>
<br>
Hello World! - Main Page
<br>
<a href="/page1.html">Goto Page 1</a>
</body>
</html> - 重複該過程以建立 page1.html 後並編輯,如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Test dotNET Site Example for AWS Elastic Beanstalk</h1>
<br>
Hello World! - Page 1
<br>
<a href="/">Goto Main Page</a>
</body>
</html> - 保存對 index.html 和 page1.html 文件的更改
- 對 axexample-dotnet 項目點擊右鍵並選擇 Publish 選項
- 在 Publish 視窗中,選擇 Web Server (IIS),然後點擊 Next 按鈕
- 選擇 Web Deploy Package ,然後點擊 Next 按鈕
- 現在,將您的 Package location 設置為 C:\axexample-dotnet\axexample-dotnet.zip ,將您的 Site name 設置為 axexample-dotnet ,然後點擊 Finish 按鈕; 如有必要,建立 C:\axexample-dotnet 資料夾來保存您的檔案
- 最後,點擊 Publish 按鈕
- 使用 Windows 檔案總管,導航到 C:\axexample-dotnet 文件夾並刪除以下文件:
- axexample-dotnet.deploy.cmd
- axexample-dotnet.deploy-readme.txt
- axexample-dotnet.SourceManifest.xml
- 在此階段, C:\axexample-dotnet 文件夾應包含以下兩個文件:
- axexample-dotnet.zip
- axexample-dotnet.SetParameters.xml
完成您的應用程序原始碼包
這個簡單的 Web 應用程序將通過以下文件結構定義:C:\axexample-dotnet\.ebextensions
C:\axexample-dotnet\.ebextensions\acesensor.config
C:\axexample-dotnet\aws-windows-deployment-manifest.json
C:\axexample-dotnet\axexample-dotnet.SetParameters.xml
C:\axexample-dotnet\axexample-dotnet.zip
C:\axexample-dotnet\dotnet-acusensor.zip
- 建立 C:\axexample-dotnet.ebextensions\acusensor.config 文件,內容如下:
files:
"C:\\Program Files\\Amazon\\ElasticBeanstalk\\hooks\\appdeploy\\post\\90create_folder.bat":
content: mkdir C:\acusensor
"C:\\Program Files\\Amazon\\ElasticBeanstalk\\hooks\\appdeploy\\post\\91extract_acusensor.bat":
content: powershell Expand-Archive -force C:\staging-previous\dotnet-acusensor.zip -DestinationPath C:\acusensor
"C:\\Program Files\\Amazon\\ElasticBeanstalk\\hooks\\appdeploy\\post\\92inject_acusensor.bat":
content: "C:\acusensor\.NET Framework\injector.exe" -m inject -t http://localhost:80/ - 新增 C:\axexample-dotnet\.ebextensions 文件夾
- 建立 C:\axexample-dotnet\aws-windows-deployment-manifest.json 文件,內容如下:
{
"manifestVersion": 1,
"deployments": {
"msDeploy": [
{
"name": "axexample-dotnet",
"parameters": {
"appBundle": "axexample-dotnet.zip",
"iisPath": "/"
}
}
]
}
} - 將您之前建立載的 dotnet-acusensor.zip 文件複製到 C:\axexample-dotnet\dotnet-acusensor.zip
- 最後,使用此命令構建原始碼包:
powershell Compress-Archive -Path C:\axexample-dotnet\* -DestinationPath %USERPROFILE%\Desktop\axexample-dotnet-aws.zip
- 保留此步驟產生的 axexample-dotnet-aws.zip 以用於下面的部署步驟
將網站部屬到 AWS Elastic Beanstalk
- 從您的 AWS 儀表板依序點擊 Elastic Beanstalk -> Environments 瀏覽
- 點擊 Create a new environment 按鈕
- 將您的環境設置為 Web server environment
- 點擊 Select 按鈕
- 到 Elastic Beanstalk -> Create environment 頁面
- 將 Application name 欄位設置為您的 Web 應用程式的名稱; 在此範例中,我們使用的名稱為 axexample-dotnet
- 將平台設定為 .NET on Windows Server
- 啟用 Upload your code 選項並點擊 Choose file 按鈕
- 選擇要上傳的 axexample-dotnet.zip 源代碼包,然後點擊 Create environment 按鈕
- 將 Application name 欄位設置為您的 Web 應用程式的名稱; 在此範例中,我們使用的名稱為 axexample-dotnet
- AWS Elastic Beanstalk 現在將創造您的環境;這可能需要幾分鐘。
- 該過程完成後,您將被發送到您環境的儀表板
- 記下由 AWS Elastic Beanstalk 自動創建的環境的新 URL:
- 您將需要它來創建 CNAME 以指向此 URL
- 在此示例中,我們將為 eb.acunetixexample.com 創建一個 CNAME以指向 axexampledotnet-env.eba-phzhexiv.us-east-1.elasticbeanstalk.com;這是使用 Namecheap cPanel 界面的範例:
- 添加 CNAME 記錄後(等待 DNS 記錄傳播後),您可以瀏覽 URL(在本例中為:http://eb.acunetixexample.com)來查看您創建的 Web 應用程式:
測試和掃描您的 Web 應用程式
將您的瀏覽器指向您的 Web 應用程序 – 在本例中為 http://eb.acunetixexample.com 以確認它正在按預期運行;你會得到以下畫面:
最後,對目標進行掃描; 面板將確認已檢測到 AcuSensor 並將其用於掃描。