I currently have a bool called debug. I want it so that when I press F10 it will set the bool to true, then if I press it again back to false and so on.
This is the code I am using:
bool debug = false;
if (cVersion < oVersion)
{
Process.Start("http://consol.cf/update.php");
return;
}
for (; ; )
{
if (debug)
{
Console.WriteLine("Please type in a command");
cmd = Console.ReadLine();
p.Send(cmd);
}
else
{
Console.WriteLine("Press enter to execute config");
Console.ReadLine();
WebConfigReader conf =
new WebConfigReader(url);
string[] tokens = Regex.Split(conf.ReadString(), #"\r?\n|\r");
foreach (string s in tokens)
//ConsoleConfig cons = new ConsoleConfig();
{
p.Send(s);
//p.Send(test);
}
}
Thanks in advance.
It depends on the exact behaviour you want. You're probably best off rolling your own version of Console.WriteLine.
The following toggles debug and instantly switch to the other mode, ignoring any partially entered command.
private static bool InterruptableReadLine(out string result)
{
var builder = new StringBuilder();
var info = Console.ReadKey(true);
while (info.Key != ConsoleKey.Enter && info.Key != ConsoleKey.F10)
{
Console.Write(info.KeyChar);
builder.Append(info.KeyChar);
info = Console.ReadKey(true);
}
Console.WriteLine();
result = builder.ToString();
return info.Key == ConsoleKey.F10;
}
// reading input, or just waiting for enter in your infinite loop
string command;
var interrupted = InterruptableReadLine(out command);
if (interrupted)
{
debug = !debug;
continue;
}
// do stuff with command if necessary
bool debug = false;
public void Toggle()
{
ConsoleKeyInfo keyinfo = Console.ReadKey();
if (keyinfo.Key == ConsoleKey.F10)
{
debug = !debug;
if(debug)
{
//Your code here if debug = true
}
else
{
//Your code here if debug = false
}
}
else
{
//Your code here if key press other than F10
}
}
ConsoleKeyInfo: Describes the console key that was pressed, including the character represented by the console key and the state of the SHIFT, ALT, and CTRL modifier keys.
Try once may it help you.
Related
I want to make an auto injection scanner in any given website and I have to use c#.
I tried some things that I found online and none of them worked for me, until i find selenium but i keep getting this error message: "OpenQA.Selenium.ElementNotInteractableException: 'element not interactable", and I have no idea why.
I didn't find anything helpful online and I think the problem may be with selenium.
I tried to find SQL, JS and BASH injections, but the script fails when i try to interact with an input. I am using OWASP juice shop to test my code.
This is my code:
static int _crntTypeOfInjection;
const int ESQL = 0, EJS = 1, EBASH = 2;
static public bool IsImportantInput(string type)
{
bool valid = false;
string[] importantTypes = new string[] { "text", "email", "password", "search", "url" };
foreach (string check in importantTypes)
{
if (type == check)
{
return true;
}
}
return false;
}
public static string getCrntInjection()
{
switch (_crntTypeOfInjection)
{
case ESQL:
return "\' OR 1=1;--";
break;
case EBASH:
return "; echo Test";
break;
case EJS:
return "<img src=\"http:\\\\url.to.file.which\\not.exist\" onerror=alert(\"JS injection success\");>";
break;
}
return "defult";
}
static public bool AttackSuccessful(string normalPage, string InjectedPage, string MainUrl, string afterClickUrl)
{
if (afterClickUrl != MainUrl || InjectedPage.Contains("Internal Server Error") || InjectedPage.Contains("JS injection success") || InjectedPage.Contains("Test"))
{
return true;
}
return false;
}
static public void Injection(string url)
{
string InjectedPage = "", NormalPage = "", AfterClickUrl = "";
var driver = new ChromeDriver("C:\\Users\\nirya\\");
driver.Url = url;
Console.WriteLine(driver.PageSource);
Actions a = new Actions(driver);
foreach (var button in driver.FindElements(By.CssSelector("button")))
{
// INJECTED PAGE
a.MoveByOffset(0, 0).Click().Perform();
foreach (IWebElement input in driver.FindElements(By.TagName("input")))
{
Console.WriteLine(input.Text);
Console.WriteLine(input.TagName);
try
{
if (IsImportantInput(input.GetAttribute("type")))
{
input.Click(); // *** HERE IS THE PROBLEM ***
input.Clear();
input.SendKeys(getCrntInjection());
}
}
catch (NoSuchElementException)
{
continue;
}
}
button.Click();
InjectedPage = driver.PageSource;
AfterClickUrl = driver.Url;
driver.Navigate().Back();
// NORMAL PAGE
a.MoveByOffset(0, 0).Click().Perform();
foreach (IWebElement input in driver.FindElements(By.CssSelector("input")))
{
try
{
if (IsImportantInput(input.GetAttribute("type")))
{
input.Clear();
input.SendKeys("normal");
}
}
catch (NoSuchElementException)
{
continue;
}
}
button.Click();
NormalPage = driver.PageSource;
driver.Navigate().Back();
if (AttackSuccessful(NormalPage, InjectedPage, url, AfterClickUrl))
{
// add to database
}
}
}
static void Main(string[] args)
{
Injection("http://localhost:3000/#/login");
}
Is there a problem with my code? Or is there another library that i can use instead?
So I would like to make a console exploit for roblox (I know its been donje before and all, but I just want to learn more!) and if you type "kill me" it would kill the player. For now I have got:
private void flatButton1_Click(object sender, EventArgs e)
{
var input = (cmdTxt.Text).ToLower();
var nl = Environment.NewLine;
if (input == "cmds")
{
consoleBox.Text = consoleBox.Text + nl + nl + "=====CMDS=====" +
nl + "kill [p] - Kills a player";
}
else if (input == "kill")
{ }
}
but I have no clue how to make it so the application reads the first command and then reads the second bit (the [p] bit), and runs that.
To make it more clear (I hope) what I would like to do is when a user types a command into the "console" it would split all the words, then recognise them, so when a user types "kill username" it would split the two, and it would get the username and kill them
You can use a Dictionary where the key is the command you want to execute and the value is a function to execute for the matching key.
void Main()
{
Dictionary<string, Action<string>> commands = new Dictionary<string, Action<string>>
{
{ "kill", RunCommand1},
{ "run", RunCommand2},
{ "jump", RunCommand3},
};
string input = Console.ReadLine();
string[] parts = input.ToLower().Split();
if (commands.ContainsKey(parts[0]))
{
string args = (parts.Length > 1 ? parts[1] : "");
commands[parts[0]].Invoke(args);
}
else
Console.WriteLine($"Command {parts[0]} not recognized");
}
void RunCommand1(string value)
{
Console.WriteLine("kill:" + value);
}
void RunCommand2(string value)
{
Console.WriteLine("run:" + value);
}
void RunCommand3(string value)
{
Console.WriteLine("jump:" + value);
}
Here you can find more info on the Action<T> delegate
I cannot figure out how to read user-input in a loop (with Console.ReadLine). I'm trying to create a note that lets me store what ever the user inputs, and exits if he types exit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Note myNote = new Note();
Note otherNote = new Note();
myNote.addText("Hi there");
Console.WriteLine(myNote.display());
otherNote.addText(Console.ReadLine());
Console.WriteLine(otherNote.display());
if (otherNote = "exit")
{
}
}
}
}
class Note
{
private string text = "";
private DateTime timeStamp = DateTime.Now;
private DateTime modifiedStamp = DateTime.Now;
int maxLength = 10;
public void addText(string sometext)
{
if (text.Length + sometext.Length < maxLength)
{
text += sometext;
modifiedStamp = DateTime.Now;
}
}
public string display()
{
return "Created: " + timeStamp.ToString() + "\n" +
"Modified: " + modifiedStamp.ToString() + "\n" +
"Content: " + text;
}
}
You need List of Notes in order to add as many notes as you want.
Additionally, you need to first save ReadLine input check if the user really asked to exit otherwise keep adding notes.
var myNotes = new List<Note>();
var firstNote = new Note();
firstNote.addText("Hi there");
Note note;
while (true)
{
var input = Console.ReadLine();
if (input.Equals("exit", StringComparison.OrdinalIgnoreCase))
{
break;
}
note = new Note();
note.addText(input);
myNotes.Add(note);
}
The general format is to use something like this (a while loop with a break condition):
// put code above while loop that only needs to be executed once
while (true) {
// get the user input for every iteration, allowing to exit at will
String line = Console.ReadLine();
if (line.Equals("exit")) {
// exit the method.
return; // use "break" if you just want to exit the loop
}
// this is what will happen in the loop body since we didn't exit
// put whatever note stuff you want to execute again and again in here
}
You'll want to edit what goes into the body of this loop depending on what exactly you want done with your note instances. But generally, you repeatedly prompt a user for input until some condition is met and then you break out of the loop. You may decided that condition (e.g. "enter 10 notes"; "type exit"; etc.)
Per #n0rd's comment, here's how a do...while loop could work:
string input;
var myNotes = new List<Note>();
do{
input = Console.ReadLine();
if (!input.Equals("exit", StringComparison.OrdinalIgnoreCase)){
var note = new Note();
note.addText(input);
myNotes.Add(note);
}
} while (!input.Equals("exit", StringComparison.OrdinalIgnoreCase));
To loop Console.ReadLine() you can use this
`List<string> al = new List<string>(); //list to store string values
while(true)
{
string f = Console.ReadLine();
if(f == null) //check if string is null or not
{
break;
}
else
al.Add(f); //add strings to list
}`
One way to do it is this:
List<string> simpleList = new List<string> { "Alpha", "Bravo", "Charlie", "Delta", "Echo" }; //Dummy data source
Console.WriteLine("Enter a call sign to find in the list. Press X to exit: "); //Prompt
string callSign;
string exitKey = "x";
while ((callSign = Console.ReadLine().ToLower()) != exitKey)
{ //This is where the "Magic" happens
if (simpleList.Contains(callSign))
{
Console.WriteLine($"\"{callSign}\" exists in our simple list");//Output should the list contain our entry
Console.WriteLine(""); //Not really relevant, just needed to added spacing between input and output
}
else
{
Console.WriteLine($"\"{callSign}\" does not exist in our simple list"); //Output should the list not contain our entry
}
Console.WriteLine("");
Console.WriteLine("Enter a call sign to find in the list. Press X to exit: ");//Prompt
}
The line:
while ((callSign = Console.ReadLine().ToLower()) != exitKey) {
...
is where the loop happens. If the entry does not equal the exitKey, the steps are repeated.
I'm working on writing a program to batch convert video files using HandbrakeCLI as the converter. I've got most of it set up and am actually working on passing the file to Handbrake now. I create a new process with the location of HandbrakeCLI and pass the arguments. I also make it so it executes in the same shell. It spins up and then starts to go through the converting and gets to three frames or so and kills itself. I'm using Visual Studio 12 on Windows 8 64 bit. Here's my code:
static void EncodeVideos()
{
var continueConverting = true;
while (continueConverting)
{
var converted = 0;
if (settings.Optimize == true)
{
videos = videos.OrderBy(x => x.InputSize).ToList();
}
foreach (var v in videos)
{
if (!v.AlreadyConverted())
{
v.CreateOutputPath();
var input = String.Format("-i \"{0}\" ", v.InputPath);
var output = String.Format("-o \"{0}\" ", v.OutputPath);
var preset = String.Format("-Z {0}", settings.Preset);
var convertString = String.Format(" {0} {1} {2}", input, output, preset);
//Converting is not working correctly yet.
var p = new Process();
p.StartInfo = new ProcessStartInfo(settings.HandBrakeLocation, convertString)
{
UseShellExecute = false,
};
p.Start();
p.WaitForExit();
converted++;
}
}
if (settings.Loop == true)
{
if (converted == 0)
{
continueConverting = false;
}
}
else
{
continueConverting = false;
}
}
}
If you would like more context for the code, I've put it all on github and you can find it on Github.
Edit: Fixed code
if (settings.Loop == true)
{
if (converted == 0)
{
continueConverting = false;
}
continueConverting = false;
}
else
{
continueConverting = false;
}
I guess you REALLY don't want to continue converting!
This looks like it's incorrect for a start.
I've just started foraying into EF, and I'm trying to get my head around it (Generally easy enough). However for some reason it's not actually saving the results, though it appears to be maybe cacheing the values for a time, and then rolling back to the previous values?
using (IAPlayerEntities IAPE = new IAPlayerEntities()) {
ObjectSet<Player> Players = IAPE.Players;
if (Players.Count() > 0) {
Player currentPlayer = new Player();
bool LoggedIn = false;
Players.DefaultIfEmpty(null);
while (!LoggedIn) {
Console.WriteLine("Please enter your Username:");
string username = Console.ReadLine();
Console.WriteLine("Please enter your Password:");
string password = MaskLine();
currentPlayer = Players.FirstOrDefault(r => r.Password == password && r.Name == username);
LoggedIn = (currentPlayer != null);
if (!LoggedIn) {
Console.WriteLine("{0}Invalid combination, please try again.", Environment.NewLine);
}
}
Console.WriteLine("{0}Please choose your colony.", Environment.NewLine);
foreach (Colony col in currentPlayer.Colonies) {
Console.WriteLine(#"{0}{1}:{0}{2}{0}Level {3}", Environment.NewLine, col.ID, col.Name, col.Level);
}
Console.WriteLine();
int colID = -1;
string colStr = Console.ReadLine();
while (!int.TryParse(colStr, out colID) || !currentPlayer.Colonies.Any(e => e.ID == colID)) {
if (colStr.ToLower() == "q") {
Console.WriteLine("Goodbye!");
return;
}
Console.WriteLine("{0}Invalid Colony. Please try again.", Environment.NewLine);
colStr = Console.ReadLine();
}
Console.WriteLine("Please enter a new name for the colony:");
string colName = Console.ReadLine();
bool b = IAPE.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Deleted | EntityState.Modified).Any();
currentPlayer.Colonies.First(e => e.ID == colID).Name = colName;
int change = IAPE.SaveChanges();
if (change >= 1) {
Console.WriteLine("{0}Colony has been renamed.", Environment.NewLine);
} else {
Console.WriteLine("{0}Colony could not be renamed.", Environment.NewLine);
}
} else {
Console.WriteLine("No Registered users");
}
}
Ignore the über secure login, it's only in there to get a player entity from it for testing.
the bool b is set to true before the save, and then if I use the debugger to run the same line in the "Immediate Window" pane then it shows false. Which to me, means it saved? And If I re-run the application after it's closed then the changed value is in place. But eventually it will return to the previous value, and if I check the database straight after it still shows the original name, so I'm not quite sure what's going on here?
It's running on VCS2010, so Framework 4.
Thanks, Psy
Checked the SQL going over to the database, and it's fine, after some investigation, turned out that I had a copy of the database within the project, which was over-riding the one in the output everytime I rebuilt it.
IAPE.Savechanges() at some point.