I'm using my TOR browser to connect to .onion websites and download data using c#. What I wanted to do, was add a button that allowed the user to get a new identity, but nothing I tried have worked so far.
I've tried using telnet, sending a webrequest to the port 9151, running a vbs that was supposed to do this, but nothing worked.
I have tried using TorSharp, but while that worked that only worked Async and I couldN't use that properly. I'm currently using com.LandonKey.SocksWebProxy.
How could I do this?
I'll add relevant code when I know what is needed, just ask.
EDIT:
#Ralph Wiggum
Sadly I can't remember every way I've tried creating a new Identity, as I've said, I tried running a VBS using Diagnostic.Process.Start(), but i doN'T have that script any more.
I also tried using WebRequest but I'm not even sure how that should be done.
This is how that looked as i can remember:
com.LandonKey.SocksWebProxy.Proxy.ProxyConfig pc = new com.LandonKey.SocksWebProxy.Proxy.ProxyConfig();
pc.SocksAddress = IPAddress.Parse(tb_Location.Text);
pc.SocksPort = 9151;
SocksWebProxy sw = new SocksWebProxy(pc);
HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create("http://127.0.0.1");
wreq.Headers.Add("SIGNAL", "AUTHENTICATE \"\"");
wreq.Headers.Add("SIGNAL", "NEWNYM");
using (var wres = wreq.GetResponse())
{
using (var s = new StreamReader(wres.GetResponseStream()))
{
MessageBox.Show(s.ReadToEnd());
}
}
I also tried using telnet (using PrimS.Telnet), and that didn't work either. That looked something like this:
CancellationToken ct = new CancellationToken();
PrimS.Telnet.Client c = new PrimS.Telnet.Client("127.0.0.1", 9151, ct);
c.WriteLine("AUTHENTICATE \"\"\n");
c.WriteLine("SIGNAL NEWNYM");
#drew010
As I said, I did use TorSharp but I stopped. It was incredibly easy to create a new identity there, but it ran entirely Async, and I couldn't manage to fix it to use it with the rest of my code.
To get a new identity using through code, you need to open a connection to the control port (usually 9051 and disabled by default [edit your torrc to add ControlPort 9051]) and issue a NEWNYM signal to establish a new circuit.
To do it you can use the TorControlClient class in TorSharp.
using Knapcode.TorSharp.Tools.Tor;
TorControlClient tc = new TorControlClient();
tc.ConnectAsync("localhost", 9051);
tc.AuthenticateAsync(null); // you should password protect your control connection
tc.SendCommandAsync("SIGNAL NEWNYM");
You can also use this batch file to request a new identity but C# is probably better for your application. Reference that code to see the sequence on the control connection for getting a new identity.
See ControlPort and HashedControlPassword configuration options.
Hope that helps.
Related
I am trying to set the default Outlook signature for both new messages and replies using C#.
Everything is working as expected for new messages (meaning that when I create a new message in Outlook, I can see the default signature), but nothing shows up when I reply to messages (or forward them).
This seems weird for two reasons:
In Outlook, I can see in the signature manager that that the default signature for replies is set properly. If I select another signature and select "Auto_Signature" again, everything starts working as expected, so it's not a problem with the signature itself.
The new messages signature is set the same way as the replies signature and that one works.
Here is the code that I am using to set the default signatures:
using Microsoft.Office.Interop.Word;
private void ApplyDefaultSignatureExecuted(object? obj)
{
var signaturesFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\Signatures");
var fileName = Path.Combine(signaturesFolder, "Auto_Signature.htm");
using (var writer = new StreamWriter(fileName))
{
writer.WriteLine("<html><body>");
writer.WriteLine("<div><p><i></span></b></p></div>");
writer.WriteLine(HttpUtility.HtmlEncode("Signature that was generated via C#"));
writer.WriteLine("</i></p><p><b><span style='font-size:24.0pt'>");
writer.WriteLine(HttpUtility.HtmlEncode("Name goes here"));
writer.WriteLine("</span></b></p></div>");
writer.WriteLine("</body></html>");
}
Application oWord = new Application();
EmailOptions oOptions = oWord.Application.EmailOptions;
oOptions.EmailSignature.NewMessageSignature = "Auto_Signature";
// This is the line that should be setting the auto-reply signature
oOptions.EmailSignature.ReplyMessageSignature = "Auto_Signature";
//Release Word, not sure if this has any effect as I get the same results with or without those lines
System.Runtime.InteropServices.Marshal.ReleaseComObject(oOptions);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
}
And here are some screenshots to go along with my explanation:
Reply - Signature does not appear automatically
Signature manager - Default signatures are set properly by C#, and changing to another one and back makes everything work as it should
New message - Signature appears automatically
According to everything I have read, this should be working since setting the signature for new message and replies is the same code, but it's not. I am using Office 365 and I don't mind switching libraries if that solves my issues.
I got it working by simply changing the line
oOptions.EmailSignature.ReplyMessageSignature = "Auto_Signature";
To
oOptions.EmailSignature.ReplyMessageSignature = oOptions.EmailSignature.NewMessageSignature;
Everything is now working exactly the same for replies and forwards as it does for new messages.
I'm trying to create a simple script that can initiate a call to a contact on Skype For Businness.
Actually, i'm trying to do it using the Lync 2013 SDK in C# but it don't seems to work. The function LyncClient.ConversationManager.AddConversation() just don't want to work and it launch a stupid exception : Microsoft.Lync.Model.LyncClientException. Of course, this exception isn't referenced on the microsoft doc...
There is almost two days i've past on it, if someone have a solution i'll be thanksfull !
First off, make sure you have a client from the LyncClient.GetClient(). Then check that the client is signed in. e.g. client.State == ClientState.SignedIn.
To make a new call you need to get the automation object from the Lync client.
automation = LyncClient.GetAutomation()
Then you use the BeginStartConversation / EndStartConversation to start the new call.
e.g.
var participantUri = new List<string> {"sip:{username}#{lyncdomain}"};
automation.EndStartConversation(automation.BeginStartConversation(AutomationModalities.Audio, participantUri, null, null, null))
Using Rotativa 1.6.4 from NuGet and have noticed the following issue using the code below.
ActionAsPdf hangs randomly for indeterminate amount of time.
Code below that is hanging:
var pdfResult = new ActionAsPdf("Report", new {id = Request.Params["id"]})
{
Cookies = cookieCollection,
FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName,
CustomSwitches = "--load-error-handling ignore"
};
Background info that may help:
The customSwitches is in use to ignore a documented issue calling wkhtmltopdf.exe using the ActionAsPdf, but it does not suppress errors in the code only in the wkhtmltopdf call.
Observations, usage and testing:
It works but when running the application (whether or not stepping through code), it can be anywhere from 10 seconds up to about 4 minutes between hitting the pdfResult = new ActionAsPdf and finally entering into the "Report" action being called. Can't discern anything actually happening in the output window of Visual Studio, no errors are being thrown that I have found. Just random slow transition into the Reports() action.
I can run the Reports() action directly via URL and it never slows like this and is quite fast for PDF generation. I am running it using the ActionAsPdf to obtain the binary to save to file system and send via email, which is the prescribed method of doing so for this library.
The behavior exists on both a local Windows 10 dev box and a remote Server 2008R2 Test box. .Net 4.5.1 on both boxes, default IIS on each.
Questions I have:
Any idea on what might cause this slow down and how to remedy it?
I ended up using UrlAsPdf() instead of ActionAsPdf() and it works. Seems there may be some issues with the ActionAsPdf() and I have filed a bug with Rotative project on GitHub. The ActionAsPdf() is still marked as beta, so hopefully it get's fixed in future versions or by the community.
In my case, I had to do few more tweaks along with using UrlAsPdf(). I have narrowed down the issue to the cookie collection that I was adding. So I tried just adding the cookie that I needed, and the issue was resolved. Following is the sample code that I have used.
var report = new UrlAsPdf(url);
Dictionary<string, string> cookieCollection = new Dictionary<string, string>();
foreach (var key in Request.Cookies.AllKeys)
{
if (Crypto.Hash("_user").Equals(key))
{
cookieCollection.Add(key, Request.Cookies.Get(key).Value);
break;
}
}
report.Cookies = cookieCollection;
report.FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName;
I try to send a code(TLRequestAuthSendCode) but it doesn't come. In what there can be a problem?
Part of code:
TLContext tlContext = new TLApiContext();
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(connections[0].getAddress(), (int)connections[0].getPort());
TLRequestAuthSendCode tlRequestAuthSendCode = new TLRequestAuthSendCode("PHONE_NUMBER",
0, 19114, "TOKEN", "en");
tlRequestAuthSendCode.serializeBody(new StreamWriter(tcpClient.GetStream()));
can you debug your code and tell if
tcpClient.Connect(connections[0].getAddress(),
Connections[0] has a value?
I'd suggest you change your code to the following:
public void run() {
connections = new ConnectionInfo[]{
new ConnectionInfo(1, 0, "149.154.167.40", 443)
};
apiState = new ApiState(connections);
doReqCode(connections);
private void doReqCode(connections){
var args = new SocketAsyncEventArgs();
I don't see where the code could break, maybe a more detailed description of your problem would be helpful
TcpClient tcpClient = new TcpClient();
As i tried the code, it mostly seemd to me as if the port was either blocked or already in use. Maybe u have a permission problem there. At least i didnt manage to get a Socket to work with the code like that.
Also i didnt dive to deep in your code, but you are using port 443. This is a reserved port with limited access.
You can get started with this, but I have written it in vb.net, not C#.
It will walk you through getting started building your own Telegram-API from scratch.
Also try and get familiar with the online documentation, it's hard but the step by step explanation I gave in that link above on generating your AuthKey, should get you started.
Good Luck
I am assigned a task on K2 Blackpearl that involves programmatically stopping the process of certain workitems directly without using the product's interface as it does not serve the purpose.
The problem is that in this business requirement, a specific proponent can have multiple document uploads which was possible by making a custom application that reads rows from an excel file and uploading to K2 automatically.
The developers of this solution are no longer present and the details of their work are unavailable.
I am just told that stopping of processes can be done using a custom console application.
Can someone please teach me the right path?
I have no prior experience on K2 so this is a huge task for me as I am unfamiliar with its flow.
K2 APIs are very well documented with sample code and demo applications you can download from K2 underground.
The answer to your question is here:
k2underground.com/forums/p/12082/35429.aspx
I've pulled out the relevant lines of code:
// references
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SourceCode.Workflow.Management;
using SourceCode.Hosting.Client.BaseAPI;
// code
// connection string
SCConnectionStringBuilder scBuilder = new SCConnectionStringBuilder();
scBuilder.Authenticate = true;
scBuilder.IsPrimaryLogin = true;
scBuilder.Integrated = true;
scBuilder.Host = "localhost";
scBuilder.Port = 5555;
// connect to K2 Server
WorkflowManagementServer wfmServer = new WorkflowManagementServer();
wfmServer.CreateConnection();
wfmServer.Connection.Open(scBuilder.ConnectionString);
// optionally get a list of process instances to explore
/*
ProcessInstances procInst =
wfmServer.GetProcessInstancesAll(string.Empty, string.Empty, string.Empty);
*/
// when you've got a proc inst you're interested in, stop it.
int _procInstId = 123; // get this from your process instance context
wfmServer.StopProcessInstances(_procInstId);
You can find more code samples here:
Tim Byrne's blog re: K2
Out of dozens of available namespaces in the API, the most common namespaces in use are (by the way, the name of the company is SourceCode):
> Sourcecode.Workflow.Client
> SourceCode.Workflow.Management
> SourceCode.SmartObjects.Client
Hope that helps.