honeypot.j 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {% import 'variables.include' as var %}
  2. ###################
  3. # HoneyPot Instance
  4. resource "aws_instance" "honeypot" {
  5. ami = data.aws_ami.ubuntu.id
  6. # ami = "${data.aws_ami.centos7.id}"
  7. instance_type = var.Honeypot-Instance-Type
  8. availability_zone = data.aws_availability_zones.available.names[0]
  9. subnet_id = aws_subnet.subnet_Honeypot.id
  10. private_ip = var.Honeypot-IP-Secured
  11. ebs_optimized = var.EBS-Optimized
  12. disable_api_termination = false
  13. associate_public_ip_address = true
  14. instance_initiated_shutdown_behavior = "terminate"
  15. key_name = var.AWS-Key-Pair-Name
  16. vpc_security_group_ids = [ aws_security_group.sg_honeypot_secured_access.id ]
  17. depends_on = [ aws_internet_gateway.gw_primary ]
  18. tags = {
  19. Name = "honeypot"
  20. }
  21. root_block_device {
  22. volume_type = var.Default-Volume-Type
  23. volume_size = var.Honeypot-Volume-Size # Gigabytes
  24. delete_on_termination = true
  25. }
  26. ebs_block_device {
  27. device_name = "/dev/sdd"
  28. volume_size = var.Swap-Volume-Size
  29. volume_type = var.Swap-Volume-Type
  30. delete_on_termination = true
  31. }
  32. user_data = <<EOF
  33. #cloud-config
  34. package_update: true
  35. package_upgrade: true
  36. packages:
  37. - git
  38. - vim
  39. - wget
  40. - curl
  41. - tcpdump
  42. - python
  43. runcmd:
  44. - mkswap /dev/xvdd
  45. - swapon -a
  46. - git clone https://github.com/fdamstra/python_multithreaded_socket_logger.git /opt/multithreaded_socket_logger
  47. - bash /opt/multithreaded_socket_logger/honeypot_init.sh
  48. mounts:
  49. - [ xvdd, none, swap, sw, 0, 0 ]
  50. growpart:
  51. mode: auto
  52. devices: ['/']
  53. ignore_growroot_disabled: false
  54. power_state:
  55. delay: "+1"
  56. mode: "reboot"
  57. message: "Rebooting after first init."
  58. condition: True
  59. EOF
  60. # To reboot, add the following above the EOF line:
  61. # power_state:
  62. # delay: "+0"
  63. # mode: "reboot"
  64. # message: "Rebooting after first init."
  65. # condition: True
  66. # Fix issues with cached keys. Arguably less secure, but also way less annoying
  67. provisioner "local-exec" {
  68. command = "ssh-keygen -f ~/.ssh/known_hosts -R honeypot.lab.${var.Domain-Name}"
  69. }
  70. }
  71. # Create the "bad" network interface
  72. resource "aws_network_interface" "honeypot_if" {
  73. subnet_id = aws_subnet.subnet_Honeypot.id
  74. security_groups = [aws_security_group.sg_all_open.id]
  75. private_ips = [var.Honeypot-IP-Unsecured]
  76. attachment {
  77. instance = aws_instance.honeypot.id
  78. device_index = 1
  79. }
  80. }
  81. # Give bad interface an EIP
  82. resource "aws_eip" "eip_honeypot" {
  83. vpc = true
  84. network_interface = aws_network_interface.honeypot_if.id
  85. }
  86. # Give me the IP Addresses
  87. output "honeypot_mgmt_ip" {
  88. value = aws_instance.honeypot.public_ip
  89. }
  90. output "honeypot_untrusted_ip" {
  91. value = aws_eip.eip_honeypot.public_ip
  92. }
  93. # Give me DNS entries
  94. resource "aws_route53_record" "honeypot" {
  95. zone_id = var.Domain-Zone-ID
  96. name = "honeypot.lab.${var.Domain-Name}"
  97. type = "A"
  98. ttl = "300"
  99. records = [ aws_instance.honeypot.public_ip ]
  100. }
  101. resource "aws_route53_record" "honeypot_pvt" {
  102. zone_id = var.Domain-Zone-ID
  103. name = "honeypot_pvt.lab.${var.Domain-Name}"
  104. type = "A"
  105. ttl = "300"
  106. records = [aws_instance.honeypot.private_ip]
  107. }
  108. output "honeypot_dns" {
  109. value = aws_route53_record.honeypot.name
  110. }