Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemDellai committed Mar 21, 2024
1 parent 22db36d commit fa3e675
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 128 deletions.
6 changes: 4 additions & 2 deletions _egress_proxy/aci-mitmproxy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ resource "azurerm_container_group" "aci-mitmproxy" {
commands = [
"/bin/bash",
"-c",
"mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false"
"apt update -y; apt install wget -y; wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca-cert.pem'; wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca.pem'; wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca-cert.p12'; mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false --certs *=./mitmproxy-ca.pem --set confdir=./",
# EOF
# "mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false"
# "apt update -y; apt install wget -y; wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/cert.pem'; mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false --certs *=cert.pem"
]

Expand Down Expand Up @@ -50,6 +52,6 @@ resource "azurerm_container_group" "aci-mitmproxy" {
# }
# }

output "aci-mitmproxy-public_ip" {
output "aci_mitmproxy_public_ip" {
value = azurerm_container_group.aci-mitmproxy.ip_address
}
3 changes: 2 additions & 1 deletion _egress_proxy/aks-proxy-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"noProxy": [
"localhost",
"127.0.0.1",
"docker.io"
"docker.io",
"docker.com"
],
"trustedCA": "LS0tLS1CRUdJTiBDRVJUSUZJQ0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EQWZCZ05WSFNNRUdEQVdnQlN1Y2VBWXQ2NE96Wk1XUXp3Q3BvZWVvRHk4VURBUEJnTlZIUk1CQWY4RUJUQUQKQVFIL01BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRQkswdFdybDZ3b1dDUCs1bS81VWx4SWl3MnE2d1QvdVQwVgpCR2J5QllYTGZKcms5L1lXQVBZR05yaFdmekhVQU8vaEIrbVY5TDU2UlU3NHAvYk51MXdqdGZuT0phRjl5YmUwCmhyMFNsaDlkdFdvRnBHeFVzMGlFVVFHNmhEVzM5bDg2TTlweVJ6NFYrWjVGVHMvMEkya2NTUk1ySk9PZk5JZm4KMkJiVSs4Z1FUV0U5L3gvcThOcWJocUZxSUQybkZXWjl4aUlvWG1GSmt5T3hNeU1ZS2RyTERERUlHa2ZEWHhqNQphUHp1Y3l4S0ZBVzNtbWEwd1Y3WEZFdE8yYjVDMkh1YjdEN2RlbDBkSzFmZUsveWR6Z2szaTdIREFvaFZKSFlLCmZxVzVZWlpNMjkyLzY1VThPaWJmNmtjYTNZOGRFTFRPYzkxRUdPdkt2SVBJQVQvdTFFTmgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo="
}
10 changes: 5 additions & 5 deletions _egress_proxy/aks.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
resource "azurerm_kubernetes_cluster" "aks" {
name = "aks-cluster129"
name = "aks-cluster"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
dns_prefix = "aks"
kubernetes_version = "1.28.5" # "1.29.0"
kubernetes_version = "1.29.0"

network_profile {
network_plugin = "azure" # "kubenet"
Expand All @@ -25,9 +25,9 @@ resource "azurerm_kubernetes_cluster" "aks" {
}

http_proxy_config {
http_proxy = "http://${azurerm_public_ip.pip-vm-proxy.ip_address}:8080/" # "http://${azurerm_network_interface.nic-vm-proxy.private_ip_address}:8080/" # "http://${azurerm_public_ip.pip-vm-proxy.ip_address}:8080/" # "http://${azurerm_container_group.aci-mitmproxy.ip_address}:8080/" # "http://20.76.37.30:8080/"
https_proxy = "https://${azurerm_public_ip.pip-vm-proxy.ip_address}:8080/" # "https://${azurerm_network_interface.nic-vm-proxy.private_ip_address}:8080/" # "http://20.76.37.30:8080/"
no_proxy = ["localhost", "127.0.0.1", "docker.io"] #, azurerm_subnet.snet-aks.address_prefixes[0]]
http_proxy = "http://${azurerm_container_group.aci-mitmproxy.ip_address}:8080/" # "http://${azurerm_network_interface.nic-vm-proxy.private_ip_address}:8080/" # "http://${azurerm_public_ip.pip-vm-proxy.ip_address}:8080/" # "http://${azurerm_container_group.aci-mitmproxy.ip_address}:8080/" # "http://20.76.37.30:8080/"
https_proxy = "http://${azurerm_container_group.aci-mitmproxy.ip_address}:8080/" # "https://${azurerm_network_interface.nic-vm-proxy.private_ip_address}:8080/" # "https://${azurerm_public_ip.pip-vm-proxy.ip_address}:8080/" # "http://20.76.37.30:8080/"
no_proxy = ["localhost", "127.0.0.1", "docker.io", "docker.com"] #, azurerm_subnet.snet-aks.address_prefixes[0]]
trusted_ca = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURnekNDQW11Z0F3SUJBZ0lVUzJTOHNMblQ1bi8vNkM3QTErMG01WXJUejhRd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1VURUxNQWtHQTFVRUJoTUNSbEl4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERUtNQWdHQTFVRUF3d0JLakFlRncweU5EQXpNVFl3Ck9UUTVNemxhRncweU5EQTBNVFV3T1RRNU16bGFNRkV4Q3pBSkJnTlZCQVlUQWtaU01STXdFUVlEVlFRSURBcFQKYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWGFXUm5hWFJ6SUZCMGVTQk1kR1F4Q2pBSQpCZ05WQkFNTUFTb3dnZ0VpTU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dE8yYjVDMkh1YjdEN2RlbDBkSzFmZUsveWR6Z2szaTdIREFvaFZKSFlLCmZxVzVZWlpNMjkyLzY1VThPaWJmNmtjYTNZOGRFTFRPYzkxRUdPdkt2SVBJQVQvdTFFTmgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo="
}

Expand Down
21 changes: 0 additions & 21 deletions _egress_proxy/certificate/cert.crt

This file was deleted.

49 changes: 0 additions & 49 deletions _egress_proxy/certificate/cert.pem

This file was deleted.

10 changes: 5 additions & 5 deletions _egress_proxy/certificate/generate-cert.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
openssl genrsa -out cert.key 2048

# (Specify the mitm domain as Common Name, e.g. \*.google.com)
# openssl req -new -x509 -key cert.key -out cert.crt
# cat cert.key cert.crt > cert.pem

openssl req -new -x509 -key cert.key -out mitmproxy-ca-cert.pem
cat cert.key mitmproxy-ca-cert.pem > mitmproxy-ca.pem

cat cert.key mitmproxy-ca-cert.pem > mitmproxy-ca.pem

openssl pkcs12 -export -inkey cert.key -in mitmproxy-ca-cert.pem -out mitmproxy-ca-cert.p12


cat mitmproxy-ca-cert.pem | base64 -w0
cat mitmproxy-ca-cert.pem | base64 -w0
# sample output
# LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURnekNDQW11Z0F3SUJBZ0lVUzJTOHNMblQ1bi8vNkM3QTErMG01WXJUejhRd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1VURUxNQWtHQTFVRUJoTUNSbEl4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERUtNQWdHQTFVRUF3d0JLakFlRncweU5EQXpNVFl3Ck9UUTVNemxhRncweU5EQTBNVFV3T1RRNU16bGFNRkV4Q3pBSkJnTlZCQVlUQWtaU01STXdFUVlEVlFRSURBcFQKYjIxbExWTjBZWFJsTVNFd0h3W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SUQybkZXWjl4aUlvWG1GSmt5T3hNeU1ZS2RyTERERUlHa2ZEWHhqNQphUHp1Y3l4S0ZBVzNtbWEwd1Y3WEZFdE8yYjVDMkh1YjdEN2RlbDBkSzFmZUsveWR6Z2szaTdIREFvaFZKSFlLCmZxVzVZWlpNMjkyLzY1VThPaWJmNmtjYTNZOGRFTFRPYzkxRUdPdkt2SVBJQVQvdTFFTmgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
21 changes: 0 additions & 21 deletions _egress_proxy/certificate/mitmproxy-ca-cert (17).pem

This file was deleted.

30 changes: 8 additions & 22 deletions _egress_proxy/install-mitmproxy.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
#!/bin/bash

sudo apt update -y
# 1. install MITM proxy from official package

# wget https://downloads.mitmproxy.org/10.2.2/mitmproxy-10.2.2-linux-x86_64.tar.gz
wget https://downloads.mitmproxy.org/10.2.4/mitmproxy-10.2.4-linux-x86_64.tar.gz

# tar -xvf mitmproxy-10.2.2-linux-x86_64.tar.gz
tar -xvf mitmproxy-10.2.4-linux-x86_64.tar.gz

# # start the proxy

# ./mitmproxy

# sudo apt update -y
# [Other option] install MITM proxy using Python pip

# sudo apt install python3-pip -y

# pip3 install mitmproxy
# sudo apt install wget -y # install if not installed

# mitmproxy --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false

# sudo apt install wget -y
# MITM proxy can create a certificate for us on starting, but we will use our own certificate
# 2. download the certificate files

wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca-cert.pem'
wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca.pem'
wget 'https://raw.githubusercontent.com/HoussemDellai/docker-kubernetes-course/main/_egress_proxy/certificate/mitmproxy-ca-cert.p12'

./mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false --certs *=./mitmproxy-ca.pem --set confdir=./

# mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --certs *=cert.pem --set block_global=false

# screen -d -m mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false

# install the cert in: mitm.it

# 3. start MITM proxy with the certificate and expose the web interface

cat mitmproxy-ca-cert.pem | base64 -w0
# cat ~/.mitmproxy/mitmproxy-ca-cert.pem | base64 -w0
./mitmweb --listen-port 8080 --web-host 0.0.0.0 --web-port 8081 --set block_global=false --certs *=./mitmproxy-ca.pem --set confdir=./
2 changes: 1 addition & 1 deletion _egress_proxy/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "prefix" {
description = "Prefix for resources"
type = string
default = "66"
default = "68"
}
2 changes: 1 addition & 1 deletion _egress_proxy/vm-linux-proxy-mitm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "azurerm_linux_virtual_machine" "vm-proxy" {
priority = "Spot"
eviction_policy = "Deallocate"

# custom_data = filebase64("./install-mitmproxy.sh")
custom_data = filebase64("./install-mitmproxy.sh")

os_disk {
name = "os-disk-vm"
Expand Down

0 comments on commit fa3e675

Please sign in to comment.