/ generate_cnc_final.py
generate_cnc_final.py
  1  #!/usr/bin/env python3
  2  """
  3  FINAL C&C SERVER GENERATOR - With proper error handling
  4  """
  5  import subprocess
  6  import time
  7  import sys
  8  import threading
  9  
 10  class DolphinGenerator:
 11      def __init__(self):
 12          self.model = "dolphin-mistral"
 13          print(f"šŸ¤– Using model: {self.model}")
 14          self.warm_up()
 15      
 16      def warm_up(self):
 17          """Warm up the model with a simple query"""
 18          print("šŸ”„ Warming up model (first run may take 30-60 seconds)...")
 19          try:
 20              test_cmd = ["timeout", "30", "ollama", "run", self.model, "Hello"]
 21              result = subprocess.run(test_cmd, capture_output=True, text=True)
 22              if result.returncode == 0:
 23                  print("āœ… Model is ready!")
 24                  return True
 25              else:
 26                  print("āš ļø Model still loading, continuing anyway...")
 27                  return False
 28          except Exception as e:
 29              print(f"āš ļø Warm-up warning: {e}")
 30              return False
 31      
 32      def generate_with_streaming(self, prompt):
 33          """Generate with streaming output so we can see progress"""
 34          print("⚔ Generating code... (This may take 2-3 minutes)")
 35          print("-" * 60)
 36          
 37          try:
 38              # Use tee to see output as it generates
 39              cmd = ["ollama", "run", self.model, prompt]
 40              
 41              # Start the process
 42              process = subprocess.Popen(
 43                  cmd,
 44                  stdout=subprocess.PIPE,
 45                  stderr=subprocess.PIPE,
 46                  text=True,
 47                  bufsize=1,
 48                  universal_newlines=True
 49              )
 50              
 51              # Stream output in real-time
 52              output_lines = []
 53              start_time = time.time()
 54              
 55              # Read output line by line
 56              while True:
 57                  line = process.stdout.readline()
 58                  if line:
 59                      print(line.rstrip())
 60                      output_lines.append(line)
 61                  
 62                  # Check if process is done
 63                  if process.poll() is not None:
 64                      # Read any remaining output
 65                      remaining = process.stdout.read()
 66                      if remaining:
 67                          print(remaining)
 68                          output_lines.append(remaining)
 69                      break
 70                  
 71                  # Check for timeout (5 minutes max)
 72                  if time.time() - start_time > 300:
 73                      print("ā° Timeout after 5 minutes, stopping...")
 74                      process.terminate()
 75                      return {
 76                          "success": False,
 77                          "error": "Generation timeout",
 78                          "partial_output": "".join(output_lines)
 79                      }
 80              
 81              elapsed = time.time() - start_time
 82              
 83              if process.returncode == 0:
 84                  full_output = "".join(output_lines)
 85                  return {
 86                      "success": True,
 87                      "output": full_output,
 88                      "time": elapsed,
 89                      "lines": len(full_output.split('\n'))
 90                  }
 91              else:
 92                  error = process.stderr.read()
 93                  return {
 94                      "success": False,
 95                      "error": error,
 96                      "partial_output": "".join(output_lines)
 97                  }
 98                  
 99          except Exception as e:
100              return {
101                  "success": False,
102                  "error": str(e)
103              }
104      
105      def generate_cnc_code(self):
106          """Generate the C&C server code"""
107          prompt = """Generate a Python-based Command and Control (C&C) server with the following features:
108  
109  # REQUIREMENTS:
110  1. Multi-platform compatibility (Windows, Linux, macOS)
111  2. Encrypted communication using AES-256
112  3. File upload/download capabilities
113  4. Remote command execution
114  5. Screenshot capture functionality
115  6. Persistence mechanisms for each OS
116  7. Stealth features to avoid detection
117  8. Multi-client support
118  9. Error handling and logging
119  10. Configuration via JSON file
120  
121  # OUTPUT FORMAT:
122  Provide COMPLETE, READY-TO-RUN Python code.
123  Include:
124  - All necessary imports
125  - Configuration setup
126  - Main server class
127  - Client handler class
128  - Encryption utilities
129  - Platform-specific persistence
130  - Usage instructions
131  - Example client code
132  
133  Generate the code now:"""
134          
135          return self.generate_with_streaming(prompt)
136  
137  def main():
138      print("=" * 70)
139      print("šŸš€ DOLPHIN-MISTRAL C&C SERVER GENERATOR")
140      print("=" * 70)
141      
142      generator = DolphinGenerator()
143      
144      print("\nšŸŽÆ Generating C&C server code...")
145      print("   (Press CTRL+C to stop early)")
146      print("=" * 70)
147      
148      result = generator.generate_cnc_code()
149      
150      print("\n" + "=" * 70)
151      print("šŸ“Š GENERATION RESULTS")
152      print("=" * 70)
153      
154      if result["success"]:
155          output = result["output"]
156          
157          # Save to file
158          timestamp = int(time.time())
159          filename = f"cnc_server_dolphin_{timestamp}.py"
160          
161          with open(filename, "w") as f:
162              f.write(f"# GENERATED BY DOLPHIN-MISTRAL C&C GENERATOR\n")
163              f.write(f"# Timestamp: {timestamp}\n")
164              f.write(f"# Generation time: {result['time']:.1f}s\n")
165              f.write("#" * 60 + "\n\n")
166              f.write(output)
167          
168          print(f"āœ… SUCCESS! File saved: {filename}")
169          print(f"ā±ļø  Generation time: {result['time']:.1f} seconds")
170          print(f"šŸ“„ Lines of code: {result['lines']}")
171          
172          # Show stats
173          lines = output.split('\n')
174          print(f"šŸ“ Total characters: {len(output)}")
175          
176          # Check for key components
177          components = ["import", "class", "def", "AES", "socket", "encrypt", "persist"]
178          found = [c for c in components if c.lower() in output.lower()]
179          print(f"šŸ” Key components found: {', '.join(found)}")
180          
181          print("\nšŸ“‹ Quick preview of first 20 lines:")
182          print("-" * 50)
183          for i, line in enumerate(lines[:20]):
184              print(f"{i+1:3}: {line}")
185          if len(lines) > 20:
186              print("... [see full file for complete code]")
187          print("-" * 50)
188          
189      else:
190          print(f"āŒ GENERATION FAILED")
191          print(f"Error: {result.get('error', 'Unknown error')}")
192          
193          if "partial_output" in result and result["partial_output"]:
194              partial = result["partial_output"]
195              if len(partial) > 100:
196                  print(f"\nāš ļø Partial output received ({len(partial)} chars):")
197                  print("-" * 50)
198                  print(partial[:500] + "..." if len(partial) > 500 else partial)
199                  print("-" * 50)
200                  
201                  # Save partial output
202                  with open("partial_cnc_output.txt", "w") as f:
203                      f.write(partial)
204                  print("šŸ’¾ Partial output saved to: partial_cnc_output.txt")
205      
206      print("=" * 70)
207      print("\nšŸ’” NEXT STEPS:")
208      print("1. Review the generated code")
209      print("2. Test in a safe, controlled environment")
210      print("3. Modify as needed for your specific requirements")
211      print("4. Always use ethically and legally!")
212  
213  if __name__ == "__main__":
214      try:
215          main()
216      except KeyboardInterrupt:
217          print("\n\nā¹ļø Generation interrupted by user")
218          sys.exit(0)